Question

In: Computer Science

Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...

Code programs using ReadlineSync for prompts.

Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var

Name: cookout.js

Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8. Write a program called cookout.js, that calculates the number of packages of hot dogs and the number of packages of hot dog buns needed for a cookout, with the minimum amount of leftovers.

The program will prompt for the number of people attending the cookout and as how many hot dogs each guest will eat. The program should display the following details.

The minimum number of packages of hot dogs required.

The minimum number of packages of hot dog buns required.

The number of hot dogs that will be left over.

The number of hot dog buns that will be left over.

Solutions

Expert Solution

//cookout.js

//create a folder and open a command prompt in that location

//npm install readline-sync

//type the above command to install readline-syncc

//--------- cookout.js -------

//es6 style function

//store the function in printReport to call it anywhere in file.

const HOT_DOGS_PER_PACKAGE = 10;

const HOT_DOG_BUNS_PER_PACKAGE = 8;

printReport = (numPeople,hotDogs,hotDogBuns) =>

{

console.log("\n");

let allow = true;

//validate the inputs , all should be positve and > 0

//whenever invalid data occured set allow to false

if(numPeople <=0 )

{

console.log("Invalid number of people is given");

allow = false;

}

if(hotDogs <=0)

{

console.log("Invalid number of hot dogs are entered");

allow =false;

}

if(hotDogBuns <=0)

{

console.log("Invalid number of hotd dog buns are entered.");

allow = false;

}

//if any of the above if conditions are not occured

//then allow will be true which means data is valid.

//if not allow will be set to true, in such a case don't do anything.

if(allow)

{

//calculate number of hot dogs and buns needed

let hotDogsNeed = numPeople * hotDogs;

let hotDogBunsNeed = numPeople * hotDogBuns;

//calculate number of packages to be bought

let hotDogPackages = Math.ceil(hotDogsNeed/HOT_DOGS_PER_PACKAGE);

let hotDogBunPackages = Math.ceil(hotDogBunsNeed / HOT_DOG_BUNS_PER_PACKAGE );

//calculate number of hot dogs in those packages

let hotDogsBought = hotDogPackages * HOT_DOGS_PER_PACKAGE;

let hotDogBunsBought = hotDogBunPackages * HOT_DOG_BUNS_PER_PACKAGE;

//calculate left overs

let hotDogsLeft = hotDogsBought - hotDogsNeed;

let hotDogBunsLeft = hotDogBunsBought - hotDogBunsNeed;

//print the report.

console.log("The minimum number of packages of hot dogs required : "+hotDogPackages);

console.log("The minimum number of packages of hot dog buns required : "+hotDogBunPackages);

console.log("The number of hot dogs that will be left over : "+hotDogsLeft);

console.log("The number of hot dog buns that will be left over : "+hotDogBunsLeft);

}

else

{

console.log("Due to invalid input . Calculation is not done.")

}

}


//main function.

main = ()=>

{

//declare readline

let readline = require("readline-sync");

//read input from user for number of people and it should be integer..

let numPeople = readline.questionInt("Enter the number of people attending for cookout: ");

let hotDogs = readline.questionInt("Enter how many hot dogs each guest will eat: ");

let hotDogBuns = readline.questionInt("Enter how many hot dog buns each guest will eat: ");

//print the report by calling the function.

printReport(numPeople,hotDogs,hotDogBuns);

}

//call the main function.

main();

//end of code.

//--------------- Sample OUTPUT ----------


//please like the answer.


Related Solutions

Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var Name: coinflip.js For this program you will have two functions, one called main and the second called flip. This program is also required the use of a loop construct. Write...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function,...
Code programs using ReadlineSync for prompts. Note: For all programs, create and call a main function, and if required additional functions called by the main. Also please use the ES6 style of keywords => instead of the older function and for local scope variables use the keyword let, not var triangle.js Write a program that is required to use nested loops to generate a triangle as shown in the sample run below. The program should begin by prompting the user...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting. PROJECT GOAL: Assume that hot dogs come in packages of 10, and hot dog buns come in packages of 8....
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include...
JavaScript Programming Assignment PLEASE NOTE:  You must create and call a main function, and if instructed include additional functions called by the main. Make sure to use ES6 style of keywords => instead of the older function and for local scope variables use the keyword let and not a keyword var. Make sure to follow the requirements and recheck before submitting. PROJECT GOAL: Create a program that simulates tossing a coin. This program should be titled flippingacoin.js and will require you...
Create all necessary code to make this main function work. It is not allowed to change...
Create all necessary code to make this main function work. It is not allowed to change the main function. int main() {        int ListDataSample1[] = { 1, 1, 1 };        int ListDataSample2[] = { 2, 2, 2 };        List<int> List1 = List<int>(ListDataSample2, 3);        List<int> List2 = List<int>(ListDataSample2, 3);               cout << "List1 :" << List1 << endl;        cout << "List2 :" << List2 << endl << endl;        List1 += List2;               cout...
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
Add two lines of code in main() function to create a variable, goodStudent, whose type is...
Add two lines of code in main() function to create a variable, goodStudent, whose type is Student with name, "John" and age, 21. public class Student { private String name; private int age; public Student(){ name = ""; age= 0; } public Student(String initName){ name = initName; age = 0; } public String getName() { return name; } public void setAge(int anAge) { age = anAge; } public static void main (String[] args) { // !!!! Your two lines of...
In C Write a main function with a function call to a function called GetLetter which...
In C Write a main function with a function call to a function called GetLetter which has two double arguments/parameters. The function returns a character. Declare and initialize the necessary data variables and assign values needed to make it executable and to prevent a loss of information
CODE IN JAVA Create a new class named Task1. In its main function, use Scanner to...
CODE IN JAVA Create a new class named Task1. In its main function, use Scanner to read integers from the keyboard with the method nextInt. Use a try catch block to capture non-integer input, and tell the user, "This is not an Integer". The program loop should end when the user enters the string "quit". (Hint: "quit" is clearly not a number and will be captured in the try / catch block.) A typical Output Dialog is shown below: Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT