Please help me code the following in JAVA! Please do so in as simple way possibl
ID: 3880239 • 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:
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
import java.util.*;
class StoreSales
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
double avg = 0;
System.out.println("Enter the sales for Store 1: ");
double store1Sales = input.nextDouble();
System.out.println("Enter the sales for Store 2: ");
double store2Sales = input.nextDouble();
System.out.println("Enter the sales for Store 3: ");
double store3Sales = input.nextDouble();
System.out.println("Enter the sales threshold : ");
double threshold = input.nextDouble();
if(store1Sales > threshold && store2Sales < threshold && store3Sales < threshold)
{
System.out.println(" Store 1 did great!");
avg = avg + store1Sales;
}
else if(store2Sales > threshold && store1Sales < threshold && store3Sales < threshold)
{
System.out.println(" Store 2 did great!");
avg = store2Sales;
}
else if(store3Sales > threshold && store2Sales < threshold && store1Sales < threshold)
{
System.out.println(" Store 3 did great!");
avg = store3Sales;
}
else if(store1Sales > threshold && store2Sales > threshold)
{
System.out.println(" Store 1 and 1 did great");
avg = (store1Sales+store2Sales)/2;
}
else if(store2Sales > threshold && store3Sales > threshold)
{
System.out.println(" Store 2 and 3 did great");
avg = (store2Sales + store3Sales)/2;
}
else if(store1Sales > threshold && store3Sales > threshold)
{
System.out.println(" Store 1 and 3 did great");
avg = (store1Sales + store3Sales)/2;
}
else if(store1Sales > threshold && store2Sales > threshold && store3Sales > threshold)
{
System.out.println(" Store 1 , 2 and 3 did great");
avg = (store1Sales + store2Sales + store3Sales)/3;
}
else if(store1Sales < threshold && store2Sales < threshold && store3Sales < threshold)
System.out.println(" No store met the threshold");
if(avg > 0)
System.out.printf("The average sales for exceeding stores : %.2f",avg);
}
}
Output:
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
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 threshold
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.