POO tp_codecheck added
This commit is contained in:
parent
21e5176c03
commit
05a04d0717
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
# Tabela Exercício 1 de Strings
|
||||
|
||||
| Question | Answer |
|
||||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|
|
||||
| What is the length of the string below?<br>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?<br><br>String str = "Harry";<br>int n = str.length();<br>String mystery = str.substring(0, 1) + str.substring(n - 1, n);<br>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.<br><br>Scanner in = new Scanner(System.in);<br>String first = in.next();<br>String last = in.next();<br>System.out.println(last + ", " + first); | Q., John |
|
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,9 @@
|
|||
# Tabela Exercício 1 de Strings
|
||||
|
||||
| Question | Answer |
|
||||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|
|
||||
| What is the length of the string below?<br>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?<br><br>String str = "Harry";<br>int n = str.length();<br>String mystery = str.substring(0, 1) + str.substring(n - 1, n);<br>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.<br><br>Scanner in = new Scanner(System.in);<br>String first = in.next();<br>String last = in.next();<br>System.out.println(last + ", " + first); | Q., John |
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue