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
  • 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...

  • I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...

    I need help with the following assignment: Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message: Valid temperatures range from -20 to 130. Please reenter temperature. Before the program ends, display the...

  • Objectives – to practice these new concepts: decision-making with if, if-else, if-else-if-… switch data validation for...

    Objectives – to practice these new concepts: decision-making with if, if-else, if-else-if-… switch data validation for user input using a while (or while/do) loop nicely formatted output report with printf and format strings multiple input data sets using a while (or while/do) loop named constants PROJECT OVERVIEW This project provides a detailed payroll report for the sales staff at TheLaptopShop. The company has 3 tiers of salespeople: low, middle, high (designated by L, M, H) – based on their past...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt...

    Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt with good data and after invalid data Input OK Cancel Input dialog boxes with sample input for Property 1 Ingut X Input Enter the address for Property 1 Enter the value of Property 1: OK Cancel Input dialog boxes after invalid data entered for Property 1 Error Please enter anmumber greater than D Ester the walue of Peoperty t Console output END SALES REPORT...

  • C++ Programming Programming Project Outcomes:  Understand and use C++ functions for procedural abstraction and Functional...

    C++ Programming Programming Project Outcomes:  Understand and use C++ functions for procedural abstraction and Functional Decomposition  Develop some functions for generating numerical data from numerical inputs  Understand and utilize file input and file output to perform computing tasks Requirements: 1. You should do a functional decomposition to identify the functions that you will use in the program. These should include reading and writing the files, tallying and showing statistics, etc. 2. The program should prompt the user...

  • For this lab you will write a Java program that plays the dice game High-Low. In...

    For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

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
ADVERTISEMENT