subject

I need help with this assignment
(Calculating Sales) An online retailer sells five products whose retail prices are as follows: Product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows:

a) product number

b) quantity sold

Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.

It is a java programming course and I am using eclipse as the coding program and I think I got most of the answer (or the code to do it) but I keep getting errors.

import java. util. Scanner; // program uses class Scanner
public class fiveseventeen
{
private String buyerName; // name of the purchaser
// int instance variables are initialized to 0 by default
private int total; // sum of purchase price
private int purchaseCounter; // number of purchases made
private int product1; // count of product 1 purchases
private int product2; // count of product 2 purchases
private int product3; // count of product 3 purchases
private int product4; // count of product 4 purchases
private int product5; // count of product 5 purchases
// constructor initializes productName
public fiveseventeen( String name )
{
buyerName = name;// intitializes productName
}// end contstructor
// method to set product name
public void setBuyerName( String name )
{
buyerName = name;// store the product name
}// end method setProductName
// method to return product name
public String getBuyerName()
{
return buyerName;
}// end method getProductName
// display a welcome message to the purchaser
public void displayMessage()
{
// getBuyerName gets name of purchaser
System. out. printf( "Hello, %s! Please select the products that you wish to purchase.", getBuyerName() );
}// end method displayMessage
// input arbitrary number for product selection from user
public void inputPurchase()
{
Scanner input = new Scanner(System. in);
int selection; // product entered by user
System. out. printf( "%s\n%s\n %s\n %s\n",
"Enter a product selection using an integer in range of 1-5.",
"Type end-of-line indicator complete purchase",
"On UNIX/Linux/Mac OS X type d then press Enter",
"On Windows type z then press Enter" );
// loop until user enters sentery
while( input. hasNext() )
{
selection = input. nextInt(); // read selection
total += selection; // add selection to total
++purchaseCounter; // increment number of selections
// call the method to increment appropriate counter
( selection );
}// end method inputPurchase
}
// add 1 to appropriate counter for specified counter
private void ( int selection )
{
// determine which product number was entered
switch( selection )
{
case 1: // selection was product1
++product1; // increment product1
break;
case 2: // selection was product2
++product2; // increment product2
break;
case 3: // selection was product3
++product3; // increment product3
break;
case 4: // selection was product4
++product4; // increment product4
break;
case 5: // selection was product5
++product5; // increment product5
break;
}// end switch
} // end method
// display a report based on the selections entered
public void displayPurchaseReport()
{
System. out. println( "\nPurchases this session: ");
// if user entered at leaset on grade...
if( purchaseCounter != 0 )
{
// calculate total of all products entered
double sum = (double) total + purchaseCounter;
// output summary of results
System. out. printf( "Total of the %d products enter is %d\n", purchaseCounter, total );
System. out. printf( "The total cost is %d\n", sum );
System. out. printf( "%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n ",
"Number of each product purchased: ",
"Product 1: ", product1,
"Product 2: ", product2,
"Product 3: ", product3,
"Product 4: ", product4,
"Product 5: ", product5 );
} // end if
else // no product numbers were entered
System. out. println( "No products were entered" );
} // end method displayPurchaseReport
} // end class

In the " Scanner input = new Scanner(System. in); " I am getting some sort of an error and when I click on the message it gives me several "try this".
I don't really understand this program so any help would still help

thanks

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 13:30
Me ! evelyn is a manager in a retail unit. she wants to prepare a report on the projected profit for the next year. which function can she use? a. pmt b. round c. division d. what-if analysis
Answers: 2
question
Computers and Technology, 24.06.2019 15:30
What is the function of compilers and interpreters? how does a compiler differ from an interpreter?
Answers: 2
question
Computers and Technology, 24.06.2019 17:40
This assignment continues work on the online booking facility introduced at the end of chapter- 10. the work will be continued in the assignments for chapters 14 and 15 (a) assume that you will produce your online booking facility using an agile approach. i. suggest the kind of user research you would like to conduct for your product before iteration cycles begin. ii prioritize the requirements for your product according to business value, i.e which requirements are likely to provide the greatest business benefit, and sketch out the ux design work you would expect to undertake during the first four iteration cycles, i.e. cycle 0, and cycles 1 to 3. (b) using one of the mockup tools introduced above, generate a mockup of your product's landing page, as developed in the assignment for chapter-11 (c) using one of the patterns websites listed previously, identify suitable interaction patterns for elements of your product, and develop a software-based prototype that incorporates all the feedback and the results of the user experience mapping achieved at the end of chapter-11. if you do not have experience in using any of these, create a few html web pages to represent the basic structure of your website
Answers: 2
question
Computers and Technology, 24.06.2019 18:30
Is a type of bullying that takes place when a person intentionally posts negative information about another person that is not true.
Answers: 2
You know the right answer?
I need help with this assignment
(Calculating Sales) An online retailer sells five products w...
Questions
question
Social Studies, 08.10.2021 21:10
question
History, 08.10.2021 21:10
Questions on the website: 13722367