Java Reference
In-Depth Information
d) Test, debug and execute the Java program.
e) Process three complete sets of data.
4.17 (Gas Mileage) Drivers are concerned with the mileage their automobiles get. One driver has
kept track of several trips by recording the miles driven and gallons used for each tankful. Develop
a Java application that will input the miles driven and gallons used (both as integers) for each trip.
The program should calculate and display the miles per gallon obtained for each trip and print the
combined miles per gallon obtained for all trips up to this point. All averaging calculations should
produce floating-point results. Use class Scanner and sentinel-controlled repetition to obtain the
data from the user.
4.18 (Credit Limit Calculator) Develop a Java application that determines whether any of several
department-store customers has exceeded the credit limit on a charge account. For each customer,
the following facts are available:
a) account number
b) balance at the beginning of the month
c) total of all items charged by the customer this month
d) total of all credits applied to the customer's account this month
e) allowed credit limit.
The program should input all these facts as integers, calculate the new balance ( = beginning balance
+ charges - credits ), display the new balance and determine whether the new balance exceeds the
customer's credit limit. For those customers whose credit limit is exceeded, the program should dis-
play the message "Credit limit exceeded" .
4.19 (Sales Commission Calculator) A large company pays its salespeople on a commission basis.
The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a
salesperson who sells $5,000 worth of merchandise in a week receives $200 plus 9% of $5000, or a
total of $650. You've been supplied with a list of the items sold by each salesperson. The values of
these items are as follows:
Item Value
1 239.99
2 129.75
3 99.95
4 350.89
Develop a Java application that inputs one salesperson's items sold for last week and calculates and
displays that salesperson's earnings. There's no limit to the number of items that can be sold.
4.20 (Salary Calculator) Develop a Java application that determines the gross pay for each of
three employees. The company pays straight time for the first 40 hours worked by each employee
and time and a half for all hours worked in excess of 40. You're given a list of the employees, their
number of hours worked last week and their hourly rates. Your program should input this informa-
tion for each employee, then determine and display the employee's gross pay. Use class Scanner to
input the data.
4.21 (Find the Largest Number) The process of finding the largest value is used frequently in com-
puter applications. For example, a program that determines the winner of a sales contest would input
the number of units sold by each salesperson. The salesperson who sells the most units wins the con-
test. Write a pseudocode program, then a Java application that inputs a series of 10 integers and deter-
mines and prints the largest integer. Your program should use at least the following three variables:
a) counter : A counter to count to 10 (i.e., to keep track of how many numbers have been
input and to determine when all 10 numbers have been processed).
b) number : The integer most recently input by the user.
c) largest : The largest number found so far.
 
Search WWH ::




Custom Search