Please help me code the following in JAVA! Please do so in as simple way possibl
ID: 3880240 • Letter: P
Question
Please help me code the following in JAVA!
Please do so in as simple way possible, so I can understand!
Full points will be rewarded, thanks in advance!
~Summary
In this assignment, you will ask for the sales for three stores, named "Store 1," "Store 2," and "Store 3." You will then ask for the threshold in sales you'd like to find out which stores have exceeded. Based on those values, the program will print out a message saying which stores exceeded the threshold in sales and the average sales of the stores that exceeded the threshold. If no stores exceeded the threshold, a message is printed out saying so but no average is printed out.
Note that for this assignment, you may not use loops, even if you already know how to use loops. Also, no arrays. This will make the program trickier to write but we are practicing to think through the branching logic.
Thinking About How to Write the Program:
We can roughly break-up the program into three sections:
-Reading in the data values from the keyboard
-Doing the logical tests
-Writing out the report
Here are some questions you'll want to think about to help you with the center part:
What are all the possible cases? There are more possible cases than you might think about at first.
How will you deal with the fact the "average" sales for one store is just that store's sales but when two or three stores exceed the threshold, the averages will be calculated using different divisors?
How will you tell the reporting portion not to write an average sales amount if no one exceeds the threshold, while the reporting portion does do so for the other cases?
Note that for this program you don't have to test to see whether the input values are valid. For instance, you can assume the input will be a zero or positive double. Don't worry about writing code to detect someone entering in characters, negative numbers, etc.
Sample Output:
Here is output from three runs of the program. Your program should be able to duplicate this:
*Remember, no loops or arrays!
Enter the sales for Store 1: 21.99 Enter the sales for Store 2: 10.99 Enter the sales for Store 3: 100.99 Enter the sales threshold: 30.00 Store 3 did great! The average sales for exceeding stores: 100.99 Enter the sales for Store 1: 21.99 Enter the sales for Store 2: 10.99 Enter the sales for Store 3: 100.99 Enter the sales threshold: 20.00 Store 1 and 3 did great! The average sales for exceeding stores: 61.49 Enter the sales for Store 1: 21.99 Enter the sales for Store 2: 10.99 Enter the sales for Store 3: 100.99 Enter the sales threshold: 500.00 No store met the thresholdExplanation / Answer
Please find below code:
import java.util.Scanner;
public class StoreSales {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter sales for Store 1:");
double store1 = scan.nextDouble();
System.out.println("Enter sales for Store 2:");
double store2 = scan.nextDouble();
System.out.println("Enter sales for Store 3:");
double store3 = scan.nextDouble();
System.out.println("Enter sales threshold:");
double threshold = scan.nextDouble();
double sumOfSales = 0.0; // For storing sum of sales exceeding threshold
int salesCount = 0; // for count number of stores exceeding threshold
int s1=0,s2=0,s3=0; // For knowing which stores exceeding threshold
if(store1 > threshold){ // Condition for checking of store 1 exceeded threshold
sumOfSales = sumOfSales + store1;
salesCount++;
s1 = 1;
}
if(store2 > threshold){ // Condition for checking of store 2 exceeded threshold
sumOfSales = sumOfSales + store2;
salesCount++;
s2 = 1;
}
if(store3 > threshold){ // Condition for checking of store 3 exceeded threshold
sumOfSales = sumOfSales + store3;
salesCount++;
s3 = 1;
}
if(salesCount == 1){ // Condition for checking if only one store exceeded threshold
if(s1 == 1)
System.out.println("Store 1 did great!");
else if(s2 == 1)
System.out.println("Store 2 did great!");
else if(s3 == 1)
System.out.println("Store 3 did great!");
// Calculating and printing average of sales
System.out.println("The average sales for exceeding sales: "+ sumOfSales/salesCount);
}
else if(salesCount == 2){ // Condition for checking if two store exceeded threshold
if(s1 == 1 && s2 == 1)
System.out.println("Store 1 and Store 2 did great!");
if(s1 == 1 && s3 == 1)
System.out.println("Store 1 and Store 3 did great!");
if(s2 == 1 && s3 == 1)
System.out.println("Store 2 and Store 3 did great!");
// Calculating and printing average of sales
System.out.println("The average sales for exceeding sales: "+ (String.format("%.2f", sumOfSales/salesCount)));
}
else if(salesCount == 3){ // Condition for checking if all stores exceeded threshold
System.out.println("All stores did great!");
System.out.println("The average sales for exceeding sales: "+ (String.format("%.2f", sumOfSales/salesCount)));
}
else{ // Condition for checking if no store exceeded threshold
System.out.println("No store met the threshold");
}
scan.close();
}
}
Output:
Enter sales for Store 1:
21.99
Enter sales for Store 2:
10.99
Enter sales for Store 3:
100.99
Enter sales threshold:
30.00
Store 3 did great!
The average sales for exceeding sales: 100.99
Enter sales for Store 1:
21.99
Enter sales for Store 2:
10.99
Enter sales for Store 3:
100.99
Enter sales threshold:
20.00
Store 1 and Store 3 did great!
The average sales for exceeding sales: 61.49
Enter sales for Store 1:
21.99
Enter sales for Store 2:
10.99
Enter sales for Store 3:
100.99
Enter sales threshold:
500.00
No store met the threshold
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.