Selling a new vehicle pays a salesperson $1500. Selling a used vehicle pays a commission of 5% of the selling price. Write an interactive program that calculates a salesperson's total pay for selling two vehicles, each one of any type. The program should prompt the salesperson to enter the type and selling price of each vehicle. Use a loop. The program should then display the salesperson's total sales and total pay. Express these amounts in currency format as described in the requirements above.

Question
Asked Oct 15, 2019
9 views

Selling a new vehicle pays a salesperson $1500. Selling a used vehicle pays a commission of 5% of the selling price. Write an interactive program that calculates a salesperson's total pay for selling two vehicles, each one of any type. The program should prompt the salesperson to enter the type and selling price of each vehicle. Use a loop. The program should then display the salesperson's total sales and total pay. Express these amounts in currency format as described in the requirements above.

check_circle

Expert Answer

Step 1

In the given question, programming language is not mentioned to write the code.

So, I choose java to write the code. Below is the algorithm followed by code.

Program Algorithm-

START

Step1 Import essential packages.

Step2 Define main class and function.

Step3 Initialize the currency format.

Step4 Define Scanner class to take input.

Step5 Declare variables and their datatypes accordingly as per the usage.

Step6 Display the choices for the user to choose vehicle is new or old.

Step7 Perform operations on variables as per the choice of user.

Step8 Print the total pay and total sales and exit the.

END

Step 2

//importing package util.Scanner for input

import java.util.Scanner;

//importing package for currency format

import java.text.NumberFormat;

//declaring main class

public class Main

{

    //main method declaration

            public static void main(String[] args)

            {

                //converting number format to currency format

                NumberFormat currfor = NumberFormat.getCurrencyInstance();

                //creating Scanner object

                Scanner ob = new Scanner(System.in);

                //declaring variables

                float total_pay=0;

                float total_sales = 0;

                float pay=0; //pay

                float sales = 0; //selling price

                String type=""; //empty string

                for(int i=1;i<3;i++)

                {

                    System.out.println("Enter the price of "+ i +" vehicle");

                        sales = ob.nextInt();

                    total_sales = total_sales + sales; //calculate the total sale

            while (true)

            {

                     System.out.println("Enter the type of vehicle you want to sell, used or new");

                     type = ob.next().toLowerCase();

             if (type.equals("new")||type.equals("used"))

             {

                 break; //to break from while loop

             }

  

            }

            //to check if the type of the vehicle is new

      ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Engineering

Programing

Related Computer Engineering Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: How would i solve this question? I have the sample output but how do I make it? Write a program in p...

A: Program Instructions:Create a menu using print() function and use while loop to repeatedly show the ...

question_answer

Q: Consider a 4-way set associative cache made up of 64-bit words. The number of words per line is 8 an...

A: Cache size:The cache size can be calculated using the following formula:

question_answer

Q: 2) Identify the errors in the following programs a) 3 errorspublic class Test {public static void ma...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...

question_answer

Q: What are the mantissa and exponent values if 6.75 is represented in 8-bit binary floating-point repr...

A: Conversion of decimal to 8-bit floating point representation:Step 1: Convert the integer part of the...

question_answer

Q: Write a program called HeadsOrTails, that lets the user guess whether the flip of a coinresults in h...

A: The following variables used:coin to hold the value of random flipcoinString to hold the text value ...

question_answer

Q: Fix these codes in order to get the following output: Code: public class rinoel_Course { private Str...

A: The following is the source code which will give the same output as mentioned in the question. Also,...

question_answer

Q: how do you known when you need to use int and float? I know that int refers to intergers and float r...

A: “input” keyword in Python:In Python, the function which is used to read the input from the keyboard ...

question_answer

Q: What is the typical HTML5 tag which is migrate from HTML4 to HTML5? <content b. <section <fragment d...

A: HTML is a markup language that defines the properties and behavior of webpage. Since the release the...

question_answer

Q: Provide a functional block diagram for a concept for an autonomous transportation and/or delivery th...

A: Autonomous transportation is the evolution of transport where the vehicles are connected to create a...