In: Computer Science
Write one Java program and satisfy the following requirements:
if (letter == 'A' | | letter == 'a')
System.out.println("Excellent");
else if (letter == 'B' | | letter == 'b')
System.out.println("You can do better");
else if (letter == 'C' | | letter == 'c')
System.out.println("Try harder");
else if (letter == 'D' | | letter == 'd')
System.out.println("Try much harder");
else
System.out.println("Try another major! ");
3. Given the following tax table information, write Java code to assign the double taxRate appropriately given the double pay. Select the selection statement (if, if-else, or switch) that makes the most sense.
If pay is more than 100,000, tax rate is 40%
If pay is more than 60,000 and less than or equal to 100,000, tax rate is 30%
If pay is more than 30,000 and less than or equal to 60,000, tax rate is 20%
If pay is more than 15,000 and less than or equal to 30,000, tax rate is 10%
If pay is more than 5,000 and less than or equal to 15,000, tax rate is 5%
If pay is less than or equal to 5,000, tax rate is 0%
ANSWER:-
QUESTION (1):-
switch(letter)
{
case 'A':
case 'a':
System.out.println("Excellent");
break;
case 'B':
case 'b':
System.out.println("You can do better");
break;
case 'C':
case 'c':
System.out.println("Try harder");
break;
case 'D':
case 'd':
System.out.println("Try much harder");
break;
default:
System.out.println("Try another
major! ");
}
QUESTION (2):-
import java.util.Scanner;
class Largest
{
public static void main(String args[])
{
int x, y, z,max=0;
System.out.println("Enter three integers : ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = in.nextInt();
max=x;
if (x > y && x > z)
max=x;
else if (y > x && y > z)
max=y;
else if (z > x && z > y)
max=z;
System.out.println("Largest number : "+max);
}
}
OUTPUT:-
QUESTION (3):-
import java.util.Scanner;
class TaxRate
{
public static void main(String args[])
{
double taxRate=0,pay;
System.out.println("Enter pay : ");
Scanner in = new Scanner(System.in);
pay=in.nextDouble();
if (pay>100000)
taxRate=40;
else if (pay>60000 && pay<=100000)
taxRate=30;
else if (pay>30000 && pay<=60000)
taxRate=20;
else if (pay>15000 && pay<=30000)
taxRate=10;
else if (pay>5000 && pay<=15000)
taxRate=5;
else if (pay<=5000)
taxRate=0;
}
}