151k views
2 votes
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. Issue an error message for any invalid initials entered. For any salesperson name initial entered, further prompt a sale amount sold by the salesperson. Afterward, display the salesperson’s name and the sale amount for the salesperson.

User Andreycpp
by
4.2k points

1 Answer

4 votes

Answer:

import java.util.Scanner;

public class HomeSales

{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

String name = "";

double sale = 0.0;

System.out.print("Enter a salesperson's initial (D, E, or F ) ");

char initial = input.next().charAt(0);

initial = Character.toUpperCase(initial);

if(initial == 'D')

name = "Danielle";

else if(initial == 'E')

name = "Edward";

else if(initial == 'F')

name = "Francis";

else

System.out.println("Invalid initials entered!");

if(!name.equals("")){

System.out.print("Enter sale amount ");

sale = input.nextDouble();

System.out.println(name + " " + sale);

}

}

}

Step-by-step explanation:

*The code is in Java.

Initialize the name and sale

Ask the user to enter the initial

Convert initial to uppercase

Check the initial using if else statement and depending on the value, set the name. If a valid initial is entered, print an error.

If the name is not empty (This implies that a valid initial was entered), ask the user to enter the sale amount and print the name and sale amount

User Sottenad
by
4.3k points