diff --git a/1ano/2semestre/poo/out/production/poo/aula02/SecsToHMS.class b/1ano/2semestre/poo/out/production/poo/aula02/SecsToHMS.class index d09e420..e78b87b 100644 Binary files a/1ano/2semestre/poo/out/production/poo/aula02/SecsToHMS.class and b/1ano/2semestre/poo/out/production/poo/aula02/SecsToHMS.class differ diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/BankInterest.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/BankInterest.class new file mode 100644 index 0000000..0651117 Binary files /dev/null and b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/BankInterest.class differ diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Table.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Table.class new file mode 100644 index 0000000..15ff93c Binary files /dev/null and b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Table.class differ diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Temperature.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Temperature.class new file mode 100644 index 0000000..9c46d70 Binary files /dev/null and b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp01/Temperature.class differ diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Strings1.md b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Strings1.md new file mode 100644 index 0000000..ea8d514 --- /dev/null +++ b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Strings1.md @@ -0,0 +1,9 @@ +# Tabela Exercício 1 de Strings + +| Question | Answer | +|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------| +| What is the length of the string below?
String str = "Java Program" | 12 | +| With str as defined above, give a call to the substring method that returns the substring "gram". | str.substring(8) | +| Use the string concatenation operator to change the string variable str to contain the string "Java Programming". | str += "ming" | +| What does the following statement sequence print?

String str = "Harry";
int n = str.length();
String mystery = str.substring(0, 1) + str.substring(n - 1, n);
System.out.println(mystery); | Hy | +| Consider the following statement sequence. If the user provides the input John Q. Public, what is printed? If an error occurs, type error.

Scanner in = new Scanner(System.in);
String first = in.next();
String last = in.next();
System.out.println(last + ", " + first); | Q., John | \ No newline at end of file diff --git a/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Words.class b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Words.class new file mode 100644 index 0000000..aa87939 Binary files /dev/null and b/1ano/2semestre/poo/out/production/poo/tp_codecheck/tp02/Words.class differ diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp01/BankInterest.java b/1ano/2semestre/poo/src/tp_codecheck/tp01/BankInterest.java new file mode 100644 index 0000000..6397ad3 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp01/BankInterest.java @@ -0,0 +1,59 @@ +package tp_codecheck.tp01; + +// Solução do exercício 2 + +import java.util.Scanner; + +/** + This program updates an account balance, according to the table below: + Balance Interest Rate Charge + > $100,000.00 2.75 % $ 0.00 + > $25,000.00 2.00 % $ 0.00 + > $10,000.00 1.00 % $ 0.00 + >= $0.00 0.00 % $ 0.00 + < $0.00 0.00 % $ 25.00 + and prints out the new balance. +*/ +public class BankInterest +{ + public static void main(String[] args) + { + // Define constants + final double HI_RATE = 2.75; + final double MD_RATE = 2.00; + final double LO_RATE = 1.00; + final double ZERO_RATE = 0.00; + final double DEB_CHG = -25.00; + + final double HI_LIMIT = 100000.00; + final double MD_LIMIT = 25000.00; + final double LO_LIMIT = 10000.00; + final double ZERO_LIMIT = 0.00; + + // Print prompt to enter a current balence + System.out.print("Enter current balance: "); + + // Read balance + Scanner in = new Scanner(System.in); + double balance = in.nextDouble(); + + // Determine interest rate (or charge) based on current balance + // to compute new balance + + // Your work here + + double newBalance; + if (balance > HI_LIMIT) + newBalance = balance*(1+HI_RATE/100); + else if (balance > MD_LIMIT) + newBalance = balance*(1+MD_RATE/100); + else if (balance > LO_LIMIT) + newBalance = balance*(1+LO_RATE/100); + else if (balance < ZERO_LIMIT) + newBalance = balance+DEB_CHG; + else + newBalance = balance; + + System.out.printf("%.2f\n", newBalance); + } +} \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java b/1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java new file mode 100644 index 0000000..07fc547 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java @@ -0,0 +1,28 @@ +package tp_codecheck.tp01; + +// Solução do exercício 3 + +public class Table { + + public static void main(String[] args) { + System.out.printf("%s | %s | %s | %s\n", "n", "Hn", "log n", "Hn - log n"); + int n = 1; + while (n <= 1000000) { + double f1 = harmonic(n); + double f2 = Math.log((double)n); + System.out.printf("%d | %.3f | %.3f | %.9f\n", n, f1, f2, f1-f2); + n *= 2; + } + } + + /** + * Computes the Harmonic number Hn = 1 + 1/2 + 1/3 + ... + 1/n. + */ + private static double harmonic(int n) { + double sum = 0; + for (int i = 1; i <= n; i++) { + sum += 1/(float)i; + } + return sum; + } +} diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java b/1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java new file mode 100644 index 0000000..abb7a6c --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java @@ -0,0 +1,29 @@ +package tp_codecheck.tp01; + +// Solução do exercício 1 + +/* +This is a short Java program to convert +a temperature from Celsius to Fahrenheit. +*/ + +// You may want to import stuff here... + +import java.util.Scanner; + +public class Temperature { + // Create a Scanner to parse standard input: + private static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + // Put your code here + System.out.print("Celsius? "); + double celcius = sc.nextDouble(); + double fahrenheit = 1.8*celcius+32; + System.out.printf("%f C = %f F\n", celcius, fahrenheit); + + System.out.println("THE END"); + } +} + +// JMR 2023 \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md b/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md new file mode 100644 index 0000000..ea8d514 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md @@ -0,0 +1,9 @@ +# Tabela Exercício 1 de Strings + +| Question | Answer | +|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------| +| What is the length of the string below?
String str = "Java Program" | 12 | +| With str as defined above, give a call to the substring method that returns the substring "gram". | str.substring(8) | +| Use the string concatenation operator to change the string variable str to contain the string "Java Programming". | str += "ming" | +| What does the following statement sequence print?

String str = "Harry";
int n = str.length();
String mystery = str.substring(0, 1) + str.substring(n - 1, n);
System.out.println(mystery); | Hy | +| Consider the following statement sequence. If the user provides the input John Q. Public, what is printed? If an error occurs, type error.

Scanner in = new Scanner(System.in);
String first = in.next();
String last = in.next();
System.out.println(last + ", " + first); | Q., John | \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java b/1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java new file mode 100644 index 0000000..d2fdf36 --- /dev/null +++ b/1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java @@ -0,0 +1,12 @@ +package tp_codecheck.tp02; + +import java.util.Scanner; + +public class Words { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String word = in.next(); + word = word.charAt(word.length()-1) + word.substring(1, word.length()-1) + word.charAt(0); + System.out.println(word); + } +}