Question: java 4 . 1 0 Compare and contrast the if single - selection statement and the while iteration statement. How are these two statements similar?

java
4.10 Compare and contrast the if single-selection statement and the while iteration statement. How are these two statements similar? How are they different?
4.11 Explain what happens when a Java program attempts to divide one integer by another. What happens to the fractional part of the calculation? How can you avoid that outcome?
4.12 Describe the two ways in which control statements can be combined.
4.13 What type of iteration would be appropriate for calculating the sum of the first 100 positive integers? What type would be appropriate for calculating the sum of an arbitrary number of positive integers? Briefly describe how each of these tasks could be performed.
4.14 What is the difference between preincrementing and postincrementing a variable?
4.15 Identify and correct the errors in each of the following pieces of code. [Note: There may be more than one error in each piece of code.]
1 int x =1, total;
2 while (x <=10){
3 total += x;
4++x;
5}
1 while (x <=100)
2 total += x;
3++x;
1 while (y >0){a
2 System.out.println(y);
3++y;
4.16 What does the following program print?
1// Exercise 4.16: Mystery.java
2 public class Mystery {
3 public static void main(String[] args){
4 int x =1;
5 int total =0;
6
7 while (x <=10){
8 int y = x * x;
9 System.out.println(y);
10 total += y;
11++x;
12}
13
14 System.out.printf("Total is %d%n", total);
15}
16}
For Exercise 4.17 through Exercise 4.20, perform each of the following steps:
Read the problem statement.
Formulate the algorithm using pseudocode and top-down, stepwise refinement.
Write a Java program.
Test, debug and execute the Java program.
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 iteration 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:
account number
balance at the beginning of the month
total of all items charged by the customer this month
total of all credits applied to the customers account this month
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 customers credit limit. For those customers whose credit limit is exceeded, the program should display 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 $5,000, or a total of $650. Youve been supplied with a list of the items sold by each salesperson. The values of these items are shown in Fig. 4.33. Develop a Java application that inputs one salespersons items sold for last week and calculates and displays that salespersons earnings. Theres no limit to the number of items that can be sold.
Fig. 4.33
Item Value
1239.99
2129.75
399.95
4350.89
Item values for Exercise 4.19.
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. Youre given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee, then determine and display the employees 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 computer 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 contest. Write a pseudocode program, then a Java application that inputs a series of 10 integers and determines and prints the largest integer. Your program should use at least the following three variables:
counter:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!