Answer to Question #234884 in Java | JSP | JSF for Momo

Question #234884
Design a Java application that will allow a user to keep track of the sales of an employee. The user
should be presented with an option to enter the employee name and the sales amount.
Continuously prompt the user to enter in a sales amount for an employee until a sentinel value of
zero (0) is entered as a sale amount.
Please note that all input must occur in the Console window. Once the sentinel value has been
entered display the employee sales report.
Make use of a method to get the input from the user, another method to accumulate the sale
amounts and a final method to determine the average sale amount. In your solution make
provision if a user has entered in an invalid sale amount. Any sale amount entered that is below
zero (0) is an invalid entry.
1
Expert's answer
2021-09-08T14:16:51-0400
import java.util.Scanner;


public class SalesEmployee {




	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);


		System.out.print("Enter the employee name: ");
		String name = keyBoard.nextLine();
		float amount = 100;
		int saleNumber = 0;
		float totalSold = 0;
		while (amount != 0) {
			amount = -1;
			while (amount < 0) {
				System.out.print("Enter the sale "+(saleNumber+1)+" amount: ");
				amount = keyBoard.nextFloat();
				if (amount < 0) {
					System.out.println("You have entered a sale less than zero.\nPlease enter the sale again.");
				}
			}
			if(amount!=0) {
				totalSold += amount;
				saleNumber++;	
			}
			
		}
		float average=totalSold/(float)saleNumber;
		System.out.println("---------------------");
		System.out.println("EMPLOYEE SALES REPORT");
		System.out.println("---------------------");
		System.out.println("EMPLOYEE: " + name);
		System.out.println("TOTAL SOLD: R " + String.format("%.2f", totalSold));
		System.out.println("SALES COUNT: " + saleNumber);
		System.out.println("AVERAGE SALES: "+ String.format("%.2f", average));


		keyBoard.close();
	}


}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS