diff --git a/1ano/2semestre/poo/src/tp_codecheck/README.md b/1ano/2semestre/poo/src/tp_codecheck/README.md deleted file mode 100755 index f49dbb0..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Programação Orientada a Objetos -## Exercícios TP -### Resoluções para exercícios sugeridos nas aulas Teórico-Práticas - ---- -*Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp01/BankInterest.java b/1ano/2semestre/poo/src/tp_codecheck/tp01/BankInterest.java deleted file mode 100644 index 6397ad3..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp01/BankInterest.java +++ /dev/null @@ -1,59 +0,0 @@ -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 deleted file mode 100644 index 07fc547..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp01/Table.java +++ /dev/null @@ -1,28 +0,0 @@ -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 deleted file mode 100644 index abb7a6c..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp01/Temperature.java +++ /dev/null @@ -1,29 +0,0 @@ -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/Array1.md b/1ano/2semestre/poo/src/tp_codecheck/tp02/Array1.md deleted file mode 100644 index 82c4075..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp02/Array1.md +++ /dev/null @@ -1,23 +0,0 @@ -# Exercícios de Arrays - -## Ex1 -```java -final int LENGHT = 100; -int[] a = new int[LENGHT]; -// Code for filling a ommited -for (int = 99; i >= 0; i--) -{ - System.out.print(a[i]); - if (i > 0) { System.out.print(', '); } -} -``` - -## Ex2 -```java -int[] numbers = new int[100]; -for (int k = 0; k < numbers.length; k++) -{ - numbers[k] = k + 1; -} -``` - diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/NumberOfDays.java b/1ano/2semestre/poo/src/tp_codecheck/tp02/NumberOfDays.java deleted file mode 100644 index 401c3c1..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp02/NumberOfDays.java +++ /dev/null @@ -1,27 +0,0 @@ -package tp_codecheck.tp02; - -import java.util.Scanner; - -public class NumberOfDays { - public static void main(String[] args) - { - // Declare and initialize daysOfMonth - int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - - Scanner in = new Scanner(System.in); - System.out.print("Month (1 - 12): "); - int month = in.nextInt(); - System.out.print("Year: "); - int year = in.nextInt(); - - if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { - // It's a leap year. Adjust the entry for February - daysOfMonth[1]+=1; - } - - // Get the number of days in the given month - int days = daysOfMonth[month-1]; - - System.out.println("Number of days: " + days); - } -} diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Numbers.java b/1ano/2semestre/poo/src/tp_codecheck/tp02/Numbers.java deleted file mode 100644 index ebaa91c..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp02/Numbers.java +++ /dev/null @@ -1,17 +0,0 @@ -package tp_codecheck.tp02; - -public class Numbers { - public static void main(String[] args) { - // Different arrays will be substituted here. - int[] values = { 3, 1, 4, 1, 5, 9 }; - int[] newValues = new int[values.length/2]; - - for (int x = 0; x < values.length; x+=2) { - newValues[x/2] = values[x]; - } - - for (int i = 0; i < newValues.length; i++) { - System.out.println(newValues[i]); - } - } -} diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md b/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md deleted file mode 100644 index ea8d514..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md +++ /dev/null @@ -1,9 +0,0 @@ -# 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 deleted file mode 100644 index d2fdf36..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp02/Words.java +++ /dev/null @@ -1,12 +0,0 @@ -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); - } -} diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight1.java b/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight1.java deleted file mode 100644 index b8c314f..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight1.java +++ /dev/null @@ -1,66 +0,0 @@ -package tp_codecheck.tp03.part1; - -/** - A simulated traffic light. -*/ -public class TrafficLight1 -{ - private String color; - private int reds; - - /** - Constructs a green traffic light. - */ - public TrafficLight1() - { - this.color = "green"; - this.reds = 0; - } - - /** - Constructs a traffic light. - @param initialColor the initial color "green", "yellow", or "red" - */ - public TrafficLight1(String initialColor) - { - this.color = initialColor; - this.reds = initialColor == "red" ? 1 : 0; - } - - /** - Moves this traffic light to the next color. - */ - public void next() - { - switch (this.color) { - case "red": - this.color = "green"; - break; - case "green": - this.color = "yellow"; - break; - case "yellow": - this.color = "red"; - this.reds += 1; - break; - } - } - - /** - Returns the current color of this traffic light. - @return the current color - */ - public String getColor() - { - return this.color; - } - - /** - Counts how often this traffic light has been red. - @return the number of times this traffic light has been red - */ - public int getReds() - { - return this.reds; - } -} \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight2.java b/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight2.java deleted file mode 100644 index a929261..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp03/part1/TrafficLight2.java +++ /dev/null @@ -1,68 +0,0 @@ -package tp_codecheck.tp03.part1; - -/** - A simulated traffic light. -*/ -public class TrafficLight2 -{ - private int steps; - - /** - Constructs a green traffic light. - */ - public TrafficLight2() - { - this.steps = 0; - } - - /** - Constructs a traffic light. - @param initialColor the initial color "green", "yellow", or "red" - */ - public TrafficLight2(String initialColor) - { - switch (initialColor) { - case "green": - this.steps = 0; - break; - case "yellow": - this.steps = 1; - break; - case "red": - this.steps = 2; - break; - } - } - - /** - Moves this traffic light to the next color. - */ - public void next() - { - steps++; - } - - /** - Returns the current color of this traffic light. - @return the current color - */ - public String getColor() - { - int rem = (this.steps + 1) % 3; - if (rem == 0) - return "red"; - else if (rem == 1) - return "green"; - else - return "yellow"; - } - - /** - Counts how often this traffic light has been red. - @return the number of times this traffic light has been red - */ - public int getReds() - { - return (this.steps + 1) / 3; - } -} \ No newline at end of file diff --git a/1ano/2semestre/poo/src/tp_codecheck/tp03/part2/RentalCar.java b/1ano/2semestre/poo/src/tp_codecheck/tp03/part2/RentalCar.java deleted file mode 100644 index f10c708..0000000 --- a/1ano/2semestre/poo/src/tp_codecheck/tp03/part2/RentalCar.java +++ /dev/null @@ -1,72 +0,0 @@ -package tp_codecheck.tp03.part2; - -public class RentalCar { - private boolean rented; - private static int rentedCount = 0; - private static int availableCount = 0; - - /** - * Constructs a rental car. - */ - public RentalCar() { - // your work here - rented = false; - RentalCar.availableCount++; - } - - /** - * Get number of cars available. - * - * @return count of cars that are available - */ - public static int numAvailable() { - // your work here - return RentalCar.availableCount; - } - - /** - * Get number of cars rented. - * - * @return count of cars that are rented - */ - public static int numRented() { - // your work here - return RentalCar.rentedCount; - } - - /** - * Try to rent this car. - * - * @return true if the car was successfully rented, false if it was already - * rented - */ - public boolean rentCar() { - // your work here - if (this.rented) { - return false; - } else { - this.rented = true; - RentalCar.rentedCount++; - RentalCar.availableCount--; - return true; - } - } - - /** - * Return rented car. - * - * @return true if the car was previously rented and is now returned, - * false if it was not previously rented - */ - public boolean returnCar() { - // your work here - if (this.rented) { - this.rented = false; - RentalCar.rentedCount--; - RentalCar.availableCount++; - return true; - } else { - return false; - } - } -}