Question

Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that...

Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that prompts the user for a salesperson initial (D, E, or F). Either uppercase or lowercase initials are valid. While the user does not type Z, continue by prompting for the amount of a sale. Issue an error message for any invalid initials entered. Keep a running total of the amounts sold by each salesperson. After the user types Z or zfor an initial, display each salesperson’s total, a grand total for all sales, and the name of the salesperson with the highest total.

Please use WHILE loop. Use basic programming and don't use arrays.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class HomeSales {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       String salesperson = "";
       // Variable to store individual sales
       int salesD = 0;
       int salesE = 0;
       int salesF = 0;
       int sale;
      
       // Iterate while loop till initial is not Z or z
       while (!salesperson.equalsIgnoreCase("Z")) {
           // Ask user to enter initial
           System.out.print("Enter salesperson initial: ");
           salesperson = scan.nextLine();
          
           // Check initial using switch-case
           // add sale to respective variable
           switch (salesperson.toUpperCase()) {
           case "D":
               System.out.print("Enter sale amount: ");
               sale = Integer.parseInt(scan.nextLine());
               salesD += sale;
               break;
           case "E":
               System.out.print("Enter sale amount: ");
               sale = Integer.parseInt(scan.nextLine());
               salesE += sale;
               break;
           case "F":
               System.out.print("Enter sale amount: ");
               sale = Integer.parseInt(scan.nextLine());
               salesF += sale;
               break;
           case "Z":
               System.out.println("EXIT!!");
               break;
           default:
               System.out.println("Invalid Initials!!");
               break;
           }
           System.out.println();
       }

       // Calculate grandTotal by adding all sale
       int grandTotal = salesD + salesE + salesF;
      
       // Print result
       System.out.println("Danielle's sales: " + salesD);
       System.out.println("Edward's sales: " + salesE);
       System.out.println("Francis's sales: " + salesF);
       System.out.println("Grand Total: " + grandTotal);
      
       // Compare 3 sales with each other and print highest
       if (salesD > salesE && salesD > salesF) {
           System.out.println("Danielle has highest sale.");          
       } else if (salesE > salesD && salesE > salesF) {
           System.out.println("Edward has highest sale.");
       } else if (salesF > salesD && salesF > salesE) {
           System.out.println("Francis has highest sale.");
       }else {
           System.out.println("Sales are same");
       }
   }
}

OUTPUT-

Add a comment
Know the answer?
Add Answer to:
Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use Microsoft Visual Studio C# only, don't need a GUI. Use Console interface Danielle, Edward, and...

    Use Microsoft Visual Studio C# only, don't need a GUI. Use Console interface Danielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that prompts the user for a salesperson initial (D, E, or F). Either uppercase or lowercase initials are valid. While the user does not type Z, continue by prompting for the amount of a sale. Issue an error message for any invalid initials entered. Keep a running total of the amounts sold...

  • c# Instructions In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and...

    c# Instructions In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System. Globalization; at the top of your...

  • In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now,...

    In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format...

  • In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now,...

    In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format...

  • A - Write pseudocode B - Write A PYTHON PROGRAM Driver’s License Exam The local driver’s...

    A - Write pseudocode B - Write A PYTHON PROGRAM Driver’s License Exam The local driver’s license office has asked you to design a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an array. (Store each question’s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT