Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS200 Lab 3: Conditional Statements
This lab consists of four parts. In each of the first three parts you will write a complete Java 
application program, and in the fourth part you will write pseudocode that solves a word 
problem. For the first three parts submit hardcopies of your source code files and the output from  
running with the indicated inputs, and for the last part submit a hardcopy of your pseudocode.
In all parts you do not need to check if the user-input values are valid. In other words, don’t 
worry about whether the input values are positive, or if the Part A input tip is between 0 and 
100%, etc.
You may use any descriptive, valid identifiers for your class and variable names. Indent any if-
statements or if-else statements as done in the examples. 
Part A. Write a Java application program that calculates the tip for a restaurant check. The user 
will enter the amount of the check and the percentage of tip they wish to pay. The percentage 
should be input as an integer between 0 and 100. 
The tip is then determined by the formula:
  tip = check * perc / 100
where check is the amount of the check, perc is the tip percentage, and tip is the calculated tip 
amount.
Additionally, if the user enters less than a 15% tip you should output a message telling them they 
are being cheap. If the user enters greater than a 25% tip output a message telling them they are 
being generous.
Run your program three times with the following inputs:
Run 1: 
check: 15.50 
tip %: 10 
Run 2: 
check: 30.25
tip %: 15 
Run 3: 
check: 12.47
tip %: 33 
Part B. Write, compile, and execute a Java application program that gets two integers from the 
user and then calculates and outputs which number is larger (hint: this is similar to the example 
program Smaller.java). Assume that the input numbers will never be equal. 
Run your program twice with the following inputs:
Run 1: 
first number: 5 
second number: 10 
Run 2: 
first number: 66 
second number: 2 
Part C. Write a Java application program that determines whether or not a given amount of 
money will fill-up the user’s empty gas tank. Your program should do the following: 
1. Have the user input the number of gallons their gas tank holds, the current price-per-gallon, 
and the amount of money they want to spend. 
2. Calculate and output the amount of money required to fill-up the gas tank given the number of 
gallons it holds and the current price-per-gallon (you will need to determine the appropriate 
formula).
3. If the specified amount of money is sufficient to fill-up the gas tank, do the following:
 a. Output “ENOUGH”.
 b. Calculate and output the amount of money the user will have left-over after filling-up 
the tank.
Steps 3a and 3b must be done using separate output statements.
4. Otherwise (i.e., the specified amount of money is not enough) do the following:
 a. Output “NOT ENOUGH”.
 b. Calculate and output the amount of additional money the user will need to fill-up the 
tank.
As above, steps 4a and 4b must be done using two separate output statements.
Hint: in addition to declaring variables to hold the user-input values (step 1), you will probably 
also want to declare variables to hold the results calculated in steps 2, 3b, and 4b.
Run your program twice, with the following two sets of input. 
Run 1: 
gas tank capacity: 15.0 
price-per-gallon: 2.83 
money to spend: 50.00 
Run 2: 
gas tank capacity: 28.0 
price-per-gallon: 3.45 
money to spend: 30.00
Part D. For this part you will write pseudocode (not a Java program) that solves the following 
word problem. Handwritten answers will not be accepted.
The problem is to calculate the total bill for a pizza order. The customer will specify the number 
of pizzas they want and the number of toppings per pizza (for simplicity all pizzas in an order 
must each be ordered with the same number of toppings). Plain pizzas are $15 each. Toppings 
are normally $1.50 each per pizza, but three or more toppings are $1 each per pizza. Orders over 
$50 qualify for our special, which is $5 off the total order.