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.
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
import java.util.Scanner;
public class AverageProductCost {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double average = 0, count = 0, productCost;
String name;
while (true) {
System.out.print("Enter product name: ");
name = input.nextLine();
if(name.equalsIgnoreCase("stop")) {
break;
}
System.out.print("Enter product cost: ");
productCost = input.nextDouble();
input.nextLine(); // Consume newline
if(productCost >= 100) {
average += productCost;
count++;
}
}
average /= count;
System.out.println("Average cost of items is " + average);
}
}

Create a java program which will prompt a user to input a product and its cost....
This question has already been answered however I do
not understand the particulars of the answer. for an example why
are we importing an average class I thought that we could solve the
problem just inputting the scanner and doing the import command at
the top. Also at the bottom of the problem they increment the
counter I thought you increment the counter at the top. Is there
any way someone could do a detailed step-by-step explanation of the
actual...
Lab 7 Example Output Products that cost $100.00or mone 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: 2502 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...
Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows: Product 1 1...
What is the newline character in Java? What is white-space in user input? Answer these questions for each of these Scanner input methods: next(), nextLine(), nextInt(), nextDouble()? (a) Does the method skip white-space to ”look” for the next input value? (b) Does the method return a single word or the rest of the line? (c) Does the method leave the data on the input stream or consume it? (d) Does the method leave the newline character on the input stream?...
Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...
A class Scanner in Java can be used to get user input and its methods can be used after the following statement is executed: Scanner input = new Scanner(System.in); One of its methods nextDouble() returns the next double value from the keyboard. Now you are requested to write a method enterHeight() which displays the message "Input height: " and uses the method input.nextDouble() to get the user input. The process should be repeated until the input is non-negative. Finally the...
(a) A class Scanner in Java can be used to get user input and its methods can be used after the following statement is executed: Scanner input = new Scanner(System.in); One of its methods nextDouble() returns the next double value from the keyboard. Now you are requested to write a method enterHeight() which displays the message "Input height: " and uses the method input.nextDouble() to get the user input. The process should be repeated until the input is non-negative. Finally...
Overview: In this lab you are to write a Java program to prompt the user for an integer indicating a year and then print the calendar for that year. Objective: This lab's objective is to exercise you with the use of Java’s control statements. You are required to use exactly one while statement, one for statement and one switch statement. You will also practice on how to use some basic input methods of the Scanner class and some formatting techniques...
Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...
In Java Main method Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade. GradeBook Object Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At...