Question

In: Computer Science

JAVA program Create a class called Array Outside of the class, import the Scanner library Outside...

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:

  1. Declare an integer array that can hold the number of pizzas purchased each day for one week.
  2. Declare two additional variables one to hold the total sum of pizzas sold in a week and one to hold the average pizzas sold per day
  3. Instantiate a Scanner object
  4. Using an appropriate loop, ask the user to enter in the number of pizza for each day
    1. The program must test the entry value.
    2. If the number entered is negative, the program must display an error message and allow for the reentry of the value for that day. The program will continue to ask for a valid response until a valid response is entered.
    3. If the number is valid (greater than or equal to zero), the program will then prompt for the next value until the loop ends.
    4. Extra Credit will be given if the validation test is done via a method call.
  5. Send the array to a method that displays a title for the report as well as the number of pizzas sold for each day.
  6. Send the array to a method that calculates the sum total of pizzas sold for the week; the method returns the sum total back to main().
  7. Send the array to a method that calculates the average number of pizzas sold for the week; the method returns the average back to main().
  8. Display the following:
    1. The total number of pizzas sold for the week
    2. The average number of pizzas sold per day
    3. The total revenue from the pizza sold for the week
    4. The average revenue per day
  9. Display a thank you/goodbye message.
  10. Comment your code.

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!

Solutions

Expert Solution

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:


Related Solutions

This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
You need to create a Java class library to support a program to simulate a Point-...
You need to create a Java class library to support a program to simulate a Point- of-Sale (POS) system. General Requirements: You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; You should create identifiers with sensible names; You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve. Logical structures...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the computer user to enter his/her: • Name: a string representing the user’s first name • month of birthday: an integer representing the month of the user’s birthday • day of birthday: an integer representing the day of the user’s birthday • year of birthday: an integer representing the year of the user’s birthday Consider the following aspects that your program shall perform: VALIDATE USER’S...
Write a program in Java with a Scanner. Given an array and a number k where...
Write a program in Java with a Scanner. Given an array and a number k where k is smaller than the size of the array, write a program to find the k'th smallest element in the given array. It is given that all array elements are distinct. Example: Input: arr[] = {7,10,4,3,20,15} k = 3 Output: 7
Create a complete java program called Week_Report. The program must include two array structures, a string...
Create a complete java program called Week_Report. The program must include two array structures, a string array called DaysOfWeek and a double array called Temp_Values. Store in the DaysOfWeek array the following values (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday). Store in the Temp_Values array the following (23.5, 34.0, 20.9, 45.7, 29.3, 34.5, 32.5). Using a for loop structure output the values for the two arrays. Day of the Week Temperature Values Monday 23.5 Tuesday 34.0 Wednesday 20.9 Thursday 45.7...
Java Starter Code: import java.util.Scanner; public class GameScore { static Scanner keyboard = new Scanner(System.in); public...
Java Starter Code: import java.util.Scanner; public class GameScore { static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { int team1[] = new int[4]; int team2[] = new int[4]; for (int qtr = 0; qtr < 4; qtr++) { quarterScoring(team1, team2, qtr); } int team1Total = teamTotal(team1); int team2Total = teamTotal(team2); displayGameResults(team1, team2); if (team1Total > team2Total) { System.out.println("Team 1 has won the game!"); } else { System.out.println("Team 2 has won the game!"); } } static int teamTotal(int[]...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in);...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { // TODO code application logic here System.out.print("Enter any String: "); String str = br.readLine(); System.out.print("\nEnter the Key: "); int key = sc.nextInt(); String encrypted = encrypt(str, key); System.out.println("\nEncrypted String is: " +encrypted); String decrypted = decrypt(encrypted, key); System.out.println("\nDecrypted String is: " +decrypted); System.out.println("\n"); } public static String encrypt(String str,...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final grade for the course. Assume the following (you can hard-code these values in your program). Assignments are worth 30% Labs are worth 40% Mid-term is worth 15% Final is worth 15% Ask for the grades in each category. Store them in a double variable. Print out the final percentage grade.           For example, Final Grade Calculation Enter percentage grades in the following order. Assignments,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT