6. Given the following tax table information, write Java code to assign the doub
ID: 3762077 • Letter: 6
Question
6.
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, 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%
7.
Write a "query-controlled" loop that will continue to input int values from the user, adding
each to the int value sum, and then ask if the user has another value to input, until the user says
that there are no more values. Assume that a Scanner called “Keyboard” has been defined for keyboard input.
6.
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, 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%
7.
Write a "query-controlled" loop that will continue to input int values from the user, adding
each to the int value sum, and then ask if the user has another value to input, until the user says
that there are no more values. Assume that a Scanner called “Keyboard” has been defined for keyboard input.
Explanation / Answer
public static double taxRateCalculate(double pay){
if(pay >= 100000)
return 40;
else if(pay >= 60000)
return 30;
else if(pay >= 30000)
return 20;
else if(pay >= 15000)
return 10;
else if(pay >= 5000)
return 5;
else
return 0;
}
char c;
do{
sum += keyboard.nextInt();
System.out.println(“Want to enter other value?”);
c = keyboard.nextChar();
}while(c == ‘y’);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.