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;
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 5 images
- True or False? In Java, an array is a primitive type that need not be instantiated.arrow_forwardCode these three methods.arrow_forwardpublic class ArrayCommonOperations{ public static void main(String [] args) { //*** Task #1: Define and instantiate an array of integer numbers, with 10 elements //*** Task #2: Fill in the array with integer numbers from 1 to 100 //*** Task #3: define another array, named temp, and copy the initial array in it. //* This allows to preserve the original array //*** Task #4: Define the variables you need to calculate the following values, //* and initialize them with appropriate values. //*** Task #5: Print the original array //*** Task #6: Calculate the sum of all values //*** Task #7: Count the number of even values //*** Task #8: Calculate the minimum value in the array //*** Task #9: Calculate the maximum value in the array //*** Task #10: Replace the elements that are divisible by 3, with their value plus 2 //*** Task #11:…arrow_forward
- Please edit this class Authenticator. Remove breaks. Also create user array of size 100 rather than 3 different arrays. Also edit so it can be more OOP import java.util.Scanner; public class AuthenticatorApp { public static void main(String[] args) throws Exception { Scanner input=new Scanner(System.in); Authenticator obj=new Authenticator("user.data"); String Username,Password; boolean done=false; int count=0; while(count<3) { System.out.print("Username? "); Username=input.next(); System.out.print("Password? "); Password=input.next(); obj.authenticate(Username,Password); count++; } System.out.print("Too many failed attempts... please try again later"); input.close(); } } ------------------------------------------------------------------------------------------------------------import java.io.File; import…arrow_forwardJAVA PROGRAM ASAP *********** THIS PROGRAM MUST WORK IN HYPERGRADE AND PASS ALL THE TEST CASES. Sorting - Lab #7 Create a class called Sort that has three static methods for sorting integer arrays. All three methods should accept an array of integers, have void return type, and should sort the array in-place. 1. public static void bubbleSort(int[] array) { // your code here } 2. public static void insertionSort(int[] array) { // your code here } 3. public static void selectionSort(int[] array) { // your code here } Please enter a space separated list of numbers to sort or type QUIT to exit:\n3 2 1ENTERSorted array using Bubble Sort algorithm:\n1 2 3\nSorted array using Insertion Sort algorithm:\n1 2 3\nSorted array using Selection Sort algorithm:\n1 2 3\nPlease enter a space separated list of numbers to sort or type QUIT to exit:\nquitENTER Test Case 2 Please enter a space separated list of numbers to sort or type QUIT to exit:\n1ENTERSorted array…arrow_forwardJAVAarrow_forward
- Intellij - Java Write a program which does the following: Create a class with the main() method. Take a string array input from the user in main() method. Note: Do not hardcode the string array in code. After the String array input loop, the array should be: words[] = {"today", "is", "a", "lovely", "spring","day", "not", "too", "hot", "not", "too", "cold"}; Print the contents of this array using Arrays.toString() method. Write a method called handleString() that performs the following: Takes a String[] array as method parameter (similar to main method). Loop through the array passed as parameter, and for each word in the array: If the length of the word is even, get the index of the last letter & print that index. Use length() and indexOf() String object methods. If the string length is odd, get the character at the 1st position in the string & print that letter. Use length() and charAt() String object methods.arrow_forwardWrite a call to Arrays static method equals with arguments arrayl and array2.arrow_forwardProblem: Write a method that will determine whether a given value can be made given an array of coin values. For example, each value in the array represents a coin with that value. An array with [1, 2, 3] represents 3 coins with the values, 1, 2, and 3. Determine whether or not these values can be used to make a desired value. The coins in the array are infinite and can only be used as many times as needed. Return true if the value can be made and false otherwise. Dynamic Programming would be handy for this problem. Data: An array containing 0 or more coin values and an amount. Output: Return true or false. Sample Data ( 1, 2, 3, 12, 5 ), 3 ( 4, 15, 16, 17, 1 ), 21 ( 1 ), 5 ( 3 ), 7 Sample Output true true true falsearrow_forward
- JAVA Program Homework #1. Chapter 7. PC# 2. Payroll Class (page 488-489) Write a Payroll class that uses the following arrays as fields: * employeeId. An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 * hours. An array of seven integers to hold the number of hours worked by each employee * payRate. An array of seven doubles to hold each employee’s hourly pay rate * wages. An array of seven doubles to hold each employee’s gross wages The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeId array. That same employee’s pay rate should be stored in element 0 of the payRate array. The class should have a method that accepts an employee’s identification…arrow_forwardJAVA PROGRAM Homework #1. Chapter 7. PC# 2. Payroll Class (page 488-489) Write a Payroll class that uses the following arrays as fields: * employeeId. An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 * hours. An array of seven integers to hold the number of hours worked by each employee * payRate. An array of seven doubles to hold each employee’s hourly pay rate * wages. An array of seven doubles to hold each employee’s gross wages The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeId array. That same employee’s pay rate should be stored in element 0 of the payRate array. The class should have a method that accepts an employee’s identification…arrow_forwardpublic int binarySearch(int[]array, int num) {int low = 0;//low rangeint high = array.length -1; //high range int mid; //mid rangewhile () //while low is less than or equal to high{mid = ; //set middle range to be (low + high) /2if () { //if the array in the middle range = input number//return mid range }elseif () { //if the array in the middle range > input number//set the high value to be the mid value minus 1 }else{//set low value to be mid value plus one } }//return -1 here because that would mean that the number is not found in the loop}arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY