the user for input on the number of orders

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

code:

import java.util.Random;
import java.util.ArrayList;
import java.util.Scanner;

public class WeekendOrders
{
/**
*
* This method takes as input the scanner instance created from main and
* asks the user for input on the number of orders placed on each of the
* days on the long weekend (Saturday, Sunday, and Monday).
* Put the number of orders for each day in an array of fixed size
*
*
* @param scnr (an instance of Scanner)
* @return an array of int which includes the number of orders
* placed on each day, with one day per index of the array
*/
public static int[] getUserInput(Scanner scnr)
{
// DO NOT MODIFY THIS LINE
int[] userInput = new int[3];

// TODO: Prompt user for input on number of orders on each day
// and store in userInput


return userInput;
}


/**
*
* This method appends all the new orders for the given day onto the
* arraylist. It first generates a random int between 0-2 (inclusive).
* If the int is 0: it adds "Burger" to the prevOrders list
* If the int is 1: it adds "Fries" to the prevOrders list
* If the int is 2: it adds "Pizza" to the prevOrders list
* This process is repeated numOrders of times. The arraylist should
* include all the new orders placed on this day appended onto the input arraylist
*
* @param numOrders (number of orders placed on any given day (as an int))
* @param prevOrders (an ArrayList of String which holds the orders placed
* for the previous set of days)
* @param rand (random variable instance already declared with seed in main)
*/
public static void addOrders(int numOrders, ArrayList<String> prevOrders, Random rand)
{
// TODO: Append numOrders items to the prevOrders ArrayList using methodology
// shown in method header javadoc.

}

/** The main method should call userInput and addOrders methods
* to create arrayList of prevOrders. Then prompt user for what order
* to check and print out appropriate result.
*
* NOTE: The user input will be 1 index based when asking for an order
* (where as your array will be 0 indexed)
* For example: If the user asks for order 12, you would want to print
* the 12th position in the array, which is yourArray[11].
*
*/
public static void main(String[] args)
{
// DO NOT MODIFY THIS LINE
// CHANGING THE SEED WILL CREATE DIFFERENT RESULTS THAN OUR TEST FUNCTIONS
final int SEED = 1;
Random rand = new Random(SEED);

// TODO: Initialize variables and call getUserInput and addOrders
// All the orders for the entire weekend should be in a single ArrayList


// TODO: Ask user for what order to check and print out as appropriate
// Note method header for main: user input will be 1-indexed

return;
}
}

Repeat this number generation process for each order that day. For example if the following is called:
addorders (2, [Pizza, Burger], rand);
and the first two integers generated by rand are 1 and 0, the returned ArrayList should be [Pizza, Burger, Fries, Burger].
3. In the main method, use the above two methods to create a single ArrayList of the different orders placed over the course of the
entire long weekend. Then prompt the user asking what order to check (i.e. the 500th order across the entire weekend). You will print
out the food that was ordered for that order number, if it exists (it is possible there were not that many orders in the long weekend).
An example of input/output will be as follows below. Again, assume all user input will be non-negative numbers.
Note there is a newline after the last line in these examples. Additionally, note user input for checking order numbers will be 1-index based
(whereas your array is 0-index based!).
Example input/output when valid order number input by a user (user input is line 2 in this example below)
What order do we want to check?
1213
The 1213 order for the weekend was Burger.
Example input/output when in-valid order number input by a user (user input is line 2 in this example below)
What order do we want to check?
1213
We had less than 1213 orders this weekend.
Transcribed Image Text:Repeat this number generation process for each order that day. For example if the following is called: addorders (2, [Pizza, Burger], rand); and the first two integers generated by rand are 1 and 0, the returned ArrayList should be [Pizza, Burger, Fries, Burger]. 3. In the main method, use the above two methods to create a single ArrayList of the different orders placed over the course of the entire long weekend. Then prompt the user asking what order to check (i.e. the 500th order across the entire weekend). You will print out the food that was ordered for that order number, if it exists (it is possible there were not that many orders in the long weekend). An example of input/output will be as follows below. Again, assume all user input will be non-negative numbers. Note there is a newline after the last line in these examples. Additionally, note user input for checking order numbers will be 1-index based (whereas your array is 0-index based!). Example input/output when valid order number input by a user (user input is line 2 in this example below) What order do we want to check? 1213 The 1213 order for the weekend was Burger. Example input/output when in-valid order number input by a user (user input is line 2 in this example below) What order do we want to check? 1213 We had less than 1213 orders this weekend.
9.8 *zyLab: WeekendOrders
Write this program using an IDE. Comment and style the code according to CS 200 Style Guide. Submit the source code file (java) below.
Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct.
The goal of this problem is to help you understand one of the key advantages of using ArrayLists. Unlike Arrays which are fixed-sized,
ArrayLists allow you to change size dynamically over the course of the program.
You will implement a short program that will create an ArrayList of all the orders a restaurant takes over a long weekend (Saturday, Sunday
& Monday). The restaurant sells three items: Burgers, Fries, and Pizza. Your job is help track what the restaurant sold and allow the user to
get easy access to the previous orders. You will implement both an Array and ArrayList in this assignment to better see the advantages of
an ArrayList.
1. You will first implement the method getUserlnput which takes as input an instance of a Scanner (scnr) and returns an array of ints.
Prompt the user asking how many orders were placed on each of the days of the long weekend (Saturday through Monday). You will
read in the input from the user and put these values into the array.
An example of input/output is shown here. Note the integer inputs are user input. You can assume the user will input valid non-negative
ints.
Example input/output (User input is lines 2, 4, 6 here in this example below)
How many orders were placed Saturday?
122
How many orders were placed Sunday?
345
How many orders were placed Monday?
1205
Transcribed Image Text:9.8 *zyLab: WeekendOrders Write this program using an IDE. Comment and style the code according to CS 200 Style Guide. Submit the source code file (java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. The goal of this problem is to help you understand one of the key advantages of using ArrayLists. Unlike Arrays which are fixed-sized, ArrayLists allow you to change size dynamically over the course of the program. You will implement a short program that will create an ArrayList of all the orders a restaurant takes over a long weekend (Saturday, Sunday & Monday). The restaurant sells three items: Burgers, Fries, and Pizza. Your job is help track what the restaurant sold and allow the user to get easy access to the previous orders. You will implement both an Array and ArrayList in this assignment to better see the advantages of an ArrayList. 1. You will first implement the method getUserlnput which takes as input an instance of a Scanner (scnr) and returns an array of ints. Prompt the user asking how many orders were placed on each of the days of the long weekend (Saturday through Monday). You will read in the input from the user and put these values into the array. An example of input/output is shown here. Note the integer inputs are user input. You can assume the user will input valid non-negative ints. Example input/output (User input is lines 2, 4, 6 here in this example below) How many orders were placed Saturday? 122 How many orders were placed Sunday? 345 How many orders were placed Monday? 1205
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY