Question: Assignment Create a java program which will prompt a user to input a product and its cost. Using a while loop that will run until
Assignment
Create a java program which will prompt a user to input a product and its cost. Using a while loop that will run until the sentinel value of stop (any case) is entered, the program will look for items with a cost greater than or equal to $100.00. The program will find the average cost of those items.
Start your program as follows:
package edu.cscc; import java.util.Scanner; // TODO add comments with your name and the purpose of the program public class Main { private static Scanner input = new Scanner(System.in); public static void main(String[] args) {
String productName;
int count;
double productCost, total, average; // TODO your code goes here
} }
Note: immediately after your statement containing input.nextDouble() you will need to add the following input.nextLine() statement. This will cause the input scanner to consume the newline after your product cost. Otherwise, your program will skip the next input statement. The code should look like this:
productCost = input.nextDouble(); input.nextLine(); // Consume newline
Example Output
Products that cost $100.00 or more
Enter the product ordered - type 'stop' to end: flat screen TV
Enter the cost of the product ordered: 599.90
Enter the product ordered - type 'stop' to end: HD cable
Enter the cost of the product ordered: 25.02
Enter the product ordered - type 'stop' to end: laptop
Enter the cost of the product ordered: 1202.25
Enter the product ordered - type 'stop' to end: external drive
Enter the cost of the product ordered: 102.40
Enter the product ordered - type 'stop' to end: stop
There were 3 item(s) that had a cost of $100.00 or more
The average price of items with a cost of $100.00 or more is $634.85
End of report
Process finished with exit code 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
