Question

Assignment: Write a program that asks the user to enter today’s sales for five stores. The...

Assignment:

Write a program that asks the user to enter today’s sales for five stores. The program should then display a bar chart comparing each store’s sales. Create each bar in the bar chart bydisplaying a row or asterisks. Each asterisk should represent $100 of sales. You must use a loop to print the bar chart.

If the user enters a negative value for the sales amount, the program will keep asking the user to enter the sales amount until a positive amount is entered,

You must use methods, loops and arrays for this assignment.

Sample Run 1:

Enter today's sale for store 1 (negative value not allowed)

1000

Enter today's sale for store 2 (negative value not allowed)

1200

Enter today's sale for store 3 (negative value not allowed)

1800

Enter today's sale for store 4 (negative value not allowed)

800

Enter today's sale for store 5 (negative value not allowed)

1900

SALES BAR CHART
Store 1:**********
Store 2:************
Store 3:****************** Store 4:********
Store 5:*******************

Sample Run 2:

Enter today's sale for store 1 (negative value not allowed)

-1000

Enter today's sale for store 1 (negative value not allowed)

1000

Enter today's sale for store 2 (negative value not allowed)

1200

Enter today's sale for store 3 (negative value not allowed)

-18000

Enter today's sale for store 3 (negative value not allowed)

1800

Enter today's sale for store 4 (negative value not allowed)

CPS 2231: Computer Organization and Programming

800

Enter today's sale for store 5 (negative value not allowed)

-90

Enter today's sale for store 5 (negative value not allowed)

1900

SALES BAR CHART
Store 1:**********
Store 2:************
Store 3:****************** Store 4:********
Store 5:*******************

Please note: The name of the class must be XXX_Program1 where XXX is your Kean email id. Any other name will result in a 5 point deduction.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/* CODE IN JAVA*/

import java.util.Scanner;

public class XXX_Program1 {

    public static void getData(int[] sales){
        Scanner scan = new Scanner(System.in);//To read from user
        for(int i = 0; i < sales.length; i++) {
            System.out.print("Enter today's sale for store " + (i + 1) + " (negative value not allowed): ");
            sales[i] = scan.nextInt();//Read sales data from user
            while(sales[i] < 0){//Validate user input
                System.out.print("Enter today's sale for store " + (i + 1) + " (negative value not allowed): ");
                sales[i] = scan.nextInt();
            }
        }
    }

    public static void plotData(int[] sales){
        System.out.println("SALES BAR CHART");
        for(int i = 0; i < sales.length; i++) {//For each store
            System.out.print("Store" + (i + 1) + ": ");
            for(int j = 0; j < sales[i]/100; j++)//For each $100 plot an asterisk
                System.out.print("*");
            System.out.println();
        }
    }

    public static void main(String[] args) {

        int[] sales = new int[5];//Create an array to store sales data for 5 stores
        getData(sales);//Get sales data for each store
        plotData(sales);//Plot bar graph for sales data
    }
}

SAMPLE RUN:

PUT YOUR EMAIL ID IN PLACE OF XXX IN CLASS NAME

Add a comment
Know the answer?
Add Answer to:
Assignment: Write a program that asks the user to enter today’s sales for five stores. The...
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
  • 12. Bar Chart Write a program that asks the user to enter today’s sales for five...

    12. Bar Chart Write a program that asks the user to enter today’s sales for five stores. The program should display a bar chart comparing each store’s sales. Create each bar in the bar chart by displaying a row of asterisks. Each asterisk should represent $100 of sales. Here is an example of the program’s output: Enter today's sales for store 1: 1000 [Enter] Enter today's sales for store 2: 1200 [Enter] Enter today's sales for store 3: 1800 [Enter]...

  • Question 1 and 2 ... Visual Basic dlear the contents of the textboxes. Do not accept...

    Question 1 and 2 ... Visual Basic dlear the contents of the textboxes. Do not accept a negative value for any of the inputs. Your application should have a button clear and utilize a separate procedure to e an application that prompts the user to enter today's sales for five program should then display a simple bar graph comparing each 2. Creat stores. The stores sales. Create each bar in the bar grah by displaying a row of asterisks (*)...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Write a C program that allows the user to enter sales information for a number of...

    Write a C program that allows the user to enter sales information for a number of sales persons and compute the commissions due for each, and summary results in report form. The program should first prompt the user to enter how many sales persons to include in the analysis. The user will then be prompted for the name, number of sales commissions, and rate of commission to be paid to each sales person. A summary itemized report will follow, see...

  • Python 3: Write a program in python that asks the user to enter a number that...

    Python 3: Write a program in python that asks the user to enter a number that contains 4 digits, i.e. in the range [1000-9999]. Your program MUST take it as a number integer. Print each digit on a separate line.

  • Write a program that asks the user to enter the types of dark chocolate and the...

    Write a program that asks the user to enter the types of dark chocolate and the number of packages purchased at the SHSU@ACM freshly made store. Make sure that you display the following chart for the user to make the selection. The plain base chocolate cost $5.00. The flavor and sweetness can be added to add on various rate. Chocolate Intensity Percentage                   Flavor & Sweetness              Cost Rate             1 - 25%                                               Super Sweet                            10% 26 - 50%        ...

  • Total Sales Design a program that asks the user to enter a store’s sales for each...

    Total Sales Design a program that asks the user to enter a store’s sales for each day of the week. The amounts should be stored in an array. Use a loop to calculate the total sales for the week and display the result. Need: variable lists, IPO Chart, pseudocode, Flowchart, and working Python code. 2. Lottery Number Generator Design a program that generates a 7-digit lottery number. The program should have an Integer array with 7 elements. Write a loop...

  • In Java, write a program that will ask the user to enter the amount of a...

    In Java, write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase...

  • Write a program in JAVA that asks the user to enter an integer. Store the integers...

    Write a program in JAVA that asks the user to enter an integer. Store the integers in an array. Allow for up to 10 integers. When the user enters -1, the program should end. Print the number of integers entered as well as the number of times each integer was entered.

  • Write a console-based program ( C # ) that asks a user to enter a number...

    Write a console-based program ( C # ) that asks a user to enter a number between 1 and 10. Check if the number is between the range and if not ask the user to enter again or quit. Store the values entered in an array. Write two methods. Method1 called displayByVal should have a parameter defined where you pass the value of an array element into the method and display it. Method2 called displayByRef should have a parameter defined...

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