Control Flow
Objective
In this assignment, you will create a Java program. Requirements are given below. This assignment will test your knowledge of Control Flow (Conditional) Statements in Java.
Instructions
When you are developing console applications using Java, you must read input from users through the console. To read a string from the console as input in Java applications, you can use the Scanner class along with System.in.
Write a program that declares 1 integer variable x, and then assigns 7 to it. Write an if statement to print out “Less than 10” if x is less than 10. Change x to equal 15, and notice the result (console should not display anything).
Write a program that declares 1 integer variable x, and then assigns 7 to it. Write an if-else statement that prints out “Less than 10” if x is less than 10, and “Greater than 10” if x is greater than 10. Change x to 15 and notice the result.
Write a program that declares 1 integer variable x, and then assigns 15 to it. Write an if-else-if statement that prints out “Less than 10” if x is less than 10; “Between 10 and 20” if x is greater than 10 but less than 20, and “Greater than or equal to 20” if x is greater than or equal to 20. Change x to 50 and notice the result.
Write a program that declares 1 integer variable x, and then assigns 15 to it. Write an if-else statement that prints “Out of range” if the number is less than 10 or greater than 20 and prints “In range” if the number is between 10 and 20 (including equal to 10 or 20). Change x to 5 and notice the result.
Write a program that uses if-else-if statements to print out grades A, B, C, D, F, according to the following criteria:
A: 90-100
B: 80-89
C: 70-79
D: 60-69
F: <60 Use the Scanner class to accept a number score from the user to determine the letter grade. Print out “Score out of range” if the score is less than 0 or greater than 100.
Write a program that accepts an integer between 1 and 7 from the user. Use a switch statement to print out the corresponding weekday. Print “Out of range” if the number is less than 1 or greater than 7. Do not forget to include “break” statements in each of your cases.
Create a program that lets the users input their filing status and income. Display how much tax the user would have to pay according to status and income. The U.S. federal personal income tax is calculated based on the filing status and taxable income. There are four filing statuses: Single, Married Filing Jointly, Married Filing Separately, and Head of Household. The tax rates for 2009 are shown below:
Marginal Tax Rate | Single | Married Filing Jointly or Qualifving Widow(er) | Married Filing Separately | Head of Household |
---|---|---|---|---|
10% | $0 - $8.350 | $0 - $16,700 | $0 - $8.350 | $0-$11,950 |
15% | $8.351 - $33.950 | $16,701 - $67,900 | $8.351 - $33,950 | $11,951- $45,500 |
25% | $33,951 - $82,250 | $67,901-$137,050 | $33,951-$68,525 | $45,501 - $117.450 |
28% | $82,251- $171.550 | $137.051 - $208,850 | $68.526 - $104,425 | $117,451 - $190,200 |
33% | $171,551 - $372.950 | $208.851 - $372.950 | $104,426 - $186,475 | $190,201 - $372,950 |
35% | $372,951+ | $372,951+ | $186,476+ | $372.951+ |
Last updated