In: Computer Science
JAVA program
Create a class called Array
Outside of the class, import the Scanner library
Outside of main declare two static final variables and integer for number of days in the week and a double for the revenue per pizza (which is $8.50).
Create a method called main
Inside main:
Screen Shots:
Please enter the number of pizzas sold for
Day 1: 5
Day 2: 9
Day 3: -3
Invalid value. Please enter valid value
Day 3: 3
Day 4: 12
Day 5: 4
Day 6: 16
Day 7: 22
Pizza Calculator
Sales Report
Day 1: 5
Day 2: 9
Day 3: 3
Day 4: 12
Day 5: 4
Day 6: 16
Day 7: 22
Total Pizzas Sold for the Week: 71
Average Pizza Sold for the week: 10.1
Total Revenue for the week: $603.50
Average Revenue per day: $86.21
Thank you for using Pizza Counter. Goodbye!
Here is the code in java:
Array.java
import java.util.*;
public class Array
{
public static int days = 7;
public static double rev = 8.50;
public static void main(String[] args)
{
int d=0,tot=0;
double ftot,avg,totrev,avgrev;
int Ar[] = new int[10];
Scanner scan = new Scanner(System.in);
//Pizza value input part
System.out.println("Please enter the number of pizzas sold for");
while(d<days)
{
System.out.printf("Day %d: ", d+1);
Ar[d] = scan.nextInt();
//Check for valid input
if(Ar[d] < 0)
{
System.out.println("Invalid value. Please enter valid value");
}
else
{
tot+=Ar[d];
d++;
}
}
//Pizza value Display part
System.out.println("Pizza Calculator Sales Report:");
d=0;
while(d<days)
{
System.out.printf("Day %d: %d\n",d+1,Ar[d]);
d++;
}
//Calculation part
ftot = tot;
avg = ftot/days;
totrev = tot*rev;
avgrev = totrev/days;
System.out.printf("\nTotal Pizza sold for the Week: %d",tot);
System.out.printf("\nAverage Pizza sold for the Week: %.2f",avg);
System.out.printf("\nTotal Revenue for the Week: $%.2f",totrev);
System.out.printf("\nAverage Revenue per day: $%.2f",avgrev);
System.out.println("\nThank you for using Pizza Counter. Goodbye!");
}
}
Output: