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
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...
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...
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
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,...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT