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
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
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...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Create a program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Java the goal is to create a list class that uses an array to implement the...
Java the goal is to create a list class that uses an array to implement the interface below. I'm having trouble figuring out the remove(T element) and set(int index, T element). I haven't added any custom methods other than a simple expand method that doubles the size by 2. I would prefer it if you did not use any other custom methods. Please use Java Generics, Thank you. import java.util.*; /** * Interface for an Iterable, Indexed, Unsorted List ADT....
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main...
TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main {   public static void main( String[] args ) {     Scanner myInput = new Scanner(System.in); // Create a Scanner object     System.out.println("Enter (3) digits: ");     int W = myInput.nextInt();     int X = myInput.nextInt();     int Y = myInput.nextInt();      } } Use the tools described thus far to create additional code that will sort the integers in either monotonic ascending or descending order. Copy your code and...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT