Question

In: Computer Science

I need the program to continue asking the user for a positive value and NOT skip...

I need the program to continue asking the user for a positive value and NOT skip to the value for store 2 if a negative value is entered. This is the code so far: Thanks

public static void main(String[] args) {
  

       Scanner input = new Scanner(System.in);//scanner
       int Store [] = new int[5];//array for five int
      
       for(int i=0;i<5;i++) { // loops until five inputs are entered

           System.out.println("Enter today's sale for store "+ (i+1) +" (negative value not allowed)");

               Store [i] = input.nextInt();//allows user input
               }// end of for

       System.out.println("SALES BAR CHART");

       for(int i =0; i<5 ;i++) { // for loop to print out store number

       System.out.println("Store "+ (i+1) +": ");

       for(int j=0; j < Store [i];j =j+100) { // for loop to print number of asterisks

                   System.out.print("*");
                       }// end of for loop for asterisks
                   System.out.println();
               }// end of for loop
           }//end of main
       }//end of class

Solutions

Expert Solution

import java.util.Scanner;

public class SalesChart {

    public static void main(String[] args) {


        Scanner input = new Scanner(System.in);//scanner
        int Store[] = new int[5];//array for five int

        for (int i = 0; i < 5; i++) { // loops until five inputs are entered
            do {
                System.out.println("Enter today's sale for store " + (i + 1) + " (negative value not allowed)");
                Store[i] = input.nextInt();//allows user input
            } while (Store[i] < 0);
        }// end of for

        System.out.println("SALES BAR CHART");

        for (int i = 0; i < 5; i++) { // for loop to print out store number
            System.out.println("Store " + (i + 1) + ": ");
            for (int j = 0; j < Store[i]; j = j + 100) { // for loop to print number of asterisks
                System.out.print("*");
            }// end of for loop for asterisks
            System.out.println();
        }// end of for loop
    }//end of main
}//end of class


Related Solutions

Write a Python Program Continue to ask the user to enter a POSITIVE number until they...
Write a Python Program Continue to ask the user to enter a POSITIVE number until they type DONE to quit. The program should DOUBLE each of the digits in the number and display the original entry AND the SUM of the doubled digits. Hint: Use the // and % operators to accomplish this. Print the COUNT of entries that were invalid Examples: if the user enters 93218, the sum of the doubled digits is 18+6+4+2+16 = 46. User Entry Output...
Write a C++ program that keeps asking user to enter a positive integer number until a...
Write a C++ program that keeps asking user to enter a positive integer number until a sentinel value (999) is entered. Then for each positive number entered by the user, find out how many digits it consists. (Hint: divide a number by 10 will remove one digit from the number. You can count how many divisions it needs to bring the number to 0.) An example of executing such a program is shown below. Note that the user input is...
What it Looks Like to the User The program will loop, asking the user for a...
What it Looks Like to the User The program will loop, asking the user for a bet amount from 0 to 100 (assume dollars, you can use ints or longs). If the user types a 0 that means she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are:  BAR 7 BAR, 7 7 cherries,...
First, write a program to loop asking for a number from the user until the user...
First, write a program to loop asking for a number from the user until the user inputs a zero or until the user has input 50 numbers. Store each value in an array except the values that are divisible by 5 and display all stored values. Determine how many of the values stored in the array were divisible by 10 and display result. Next, write a function getMinMax that accepts an array of floats and the size of the array,...
JAVA - I am asking for the user to input their firstName and lastName but I...
JAVA - I am asking for the user to input their firstName and lastName but I want the method myMethod() to be able to print it when it is called. Is that possible? I'm new to Java and i'm not too sure what I should do to fix this. Also if I were to create a IF statement would I have to declare int amountDeposited; , int accountBalance; , int newBalance; in the new if statement. import java.util.Scanner; import java.util.Arrays;...
- Write a function with no input parameter which keeps asking the user to enter positive...
- Write a function with no input parameter which keeps asking the user to enter positive numbers until the user enters an invalid input. (An invalid input is an input which includes at least one alphabet, like 123d4). The program should print the Max and Min of the numbers the user had entered as well as the distance between the Max and Min. (Remember to calculate the absolute distance). The function does not return anything
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
Python 10 - (10 pts) - Implement a program that starts by asking the user to...
Python 10 - (10 pts) - Implement a program that starts by asking the user to enter a userID (i.e., a string). The program then checks whether the id entered by the user is in the list of valid users. The current user list is: ['joe', 'sue', jamal, 'sophie'] Depending on the outcome, an appropriate message should be printed. Regardless of the outcome, your function should print 'Done.' before terminating. Here is an example of a successful login: >>> Login:...
Step by step in python Write a program that will keep asking for a user input...
Step by step in python Write a program that will keep asking for a user input (until a blank line is entered) and will inform me whether what I entered was a valid number or not (without crashing). The program should use at least one try/except loop The program should include at least two custom written functions (a main() function can count as one of the two)
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT