Question

In: Computer Science

How would I prepare pseudocode and a flowchart for this? import java.util.Scanner; public class HotDogsBuns {...

How would I prepare pseudocode and a flowchart for this?

import java.util.Scanner;

public class HotDogsBuns {
   private static int HOTDOG_COUNT_PKG = 10;
   private static int BUNS_COUNT_PKG = 8;
  
   public static void main(String[] args) {
       //Scanner object to get user input
       Scanner keyboard = new Scanner(System.in);
      
       // Get number of people
       System.out.print("How many people will be competing in the contest?: ");
       int noOfPeople = keyboard.nextInt();
       keyboard.nextLine();
      
       // Get number of hotdogs per person
       System.out.print("How many hotdogs will each person be able to eat?: ");
       int countPerPerson = keyboard.nextInt();
       keyboard.nextLine();
      
       // Total HotDogs required
       int totalRequired = noOfPeople * countPerPerson;
      
       //The minimum number of packages of hotdogs required.
       int noOfHotDogPkgs = totalRequired / HOTDOG_COUNT_PKG;
       if (totalRequired % HOTDOG_COUNT_PKG != 0) {
           noOfHotDogPkgs++;
       }
       System.out.println("The minimum number of packages of hotdogs required: " + noOfHotDogPkgs);
      
       //The minimum number of packages of hotdog buns required.
       int noOfBunPkgs = totalRequired / BUNS_COUNT_PKG;
       if (totalRequired % BUNS_COUNT_PKG != 0) {
           noOfBunPkgs++;
       }
       System.out.println("The minimum number of packages of hotdog buns required: " + noOfBunPkgs);
      
       //The number of hotdogs that will be left over
       int leftOverHotDogs = (noOfHotDogPkgs * HOTDOG_COUNT_PKG) - totalRequired;
       System.out.println("The number of hotdogs that will be left over: " + leftOverHotDogs);
      
       //The number of hotdog buns that will be left over.
       int leftOverBuns = (noOfBunPkgs * BUNS_COUNT_PKG) - totalRequired;
       System.out.println("The number of hotdog buns that will be left over: " + leftOverBuns);
      
       //close the scanner
       keyboard.close();
      
   }

}

Solutions

Expert Solution

Answer: Hey dear student find the solution of your query, if you have any doubt feel free to ask. Thanks!!

Pseudocode:

Declare Integer HotDogsCountPKG, BunsCountPKG, noOfPeople, countPerPerson
Declare Integer totalRequired, noOfHotDogPkgs, noOfBunPkgs, leftOverHotDogs, leftOverBuns

Set noOfBunPkgs = 0
Set noOfHotDogPkgs = 0
Set HotDogsCountPKG = 10
Set BunsCountPKG = 8
Display "How many people will be competing in the contest?"
Input noOfPeople
Display "How many hotdogs will each person be able to eat?"
Input countPerPerson
Set totalRequired = noOfPeople * countPerPerson
Set noOfHotDogPkgs = totalRequired / HotDogsCountPKG
If totalRequired MOD HotDogsCountPKG != 0 Then
Set noOfHotDogPkgs = noOfHotDogPkgs + 1
End If
Display "The minimum number of packages of hotdogs required: ", noOfHotDogPkgs
Set noOfBunPkgs = totalRequired / BunsCountPKG
If totalRequired MOD BunsCountPKG != 0 Then
Set noOfBunPkgs = noOfBunPkgs + 1
End If
Display "The minimum number of packages of hotdog buns required: ", noOfBunPkgs
Set leftOverHotDogs = noOfHotDogPkgs * HotDogsCountPKG - totalRequired
Display "The number of hotdogs that will be left over: ", leftOverHotDogs
Set leftOverBuns = noOfBunPkgs * BunsCountPKG - totalRequired
Display "The number of hotdog buns that will be left over: ", leftOverBuns


Flowchart:


Related Solutions

How would I go about debugging this to make it work properly? import java.util.Scanner; public class...
How would I go about debugging this to make it work properly? import java.util.Scanner; public class TemperatureConverter{ public static void main(String[] args) { // Declare named constants. final double MIN_FAHRENHEIT = -459.67; // Declare the variables. double fahrenheit; double convertedDegrees; int tempScale; String tempScaleStr=""; // Creating the Scanner object Scanner keyboard = new Scanner(System.in); System.out.print("Enter the temperature in Fahrenheit: "); fahrenheit = keyboard.nextDouble(); // Set a breakpoint here // Verify the user's input if (fahrenheit > MIN_FAHRENHEIT) { // first...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public...
I needv pseudocode and a flowchart for the following java code public class AcmePay { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(System.in); int hours, shift, retirement = 0; do { System.out.print("Enter the number of hours worked (>0): "); hours = scanner.nextInt(); } while (hours <= 0); do { System.out.print("Enter shift [1 2 or 3]: "); shift = scanner.nextInt(); } while (shift < 1 || shift > 3); if (shift == 2 || shift ==...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {   ...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {    public static void main(String[] args) {        //Generate random array for test and copy that into 3 arrays        int[] arr1=new int[20];        int[] arr2=new int[20];        int[] arr3=new int[20];        int[] arr4=new int[20];        Random rand = new Random();        for (int i = 0; i < arr1.length; i++) {            //Generate random array...
What is wrong with this code and how can it be fixed? import java.util.Scanner; public class...
What is wrong with this code and how can it be fixed? import java.util.Scanner; public class admissionRequirement { public static void main(String[] args) { // TODO Auto-generated method stub Scanner myObj = new Scanner(System.in); System.out.println("What is your name?"); String name = myObj.nextLine(); System.out.println("What is your Reading Score?"); int reading = myObj.nextInt(); System.out.println("What is your Math Score?"); int math = myObj.nextInt(); System.out.println("What is your Writing Score?"); int writing = myObj.nextInt(); System.out.println("What is your Class Standing?"); int standing = myObj.nextInt(); System.out.println("What is...
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...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) {...
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Exercise { public static void main(String[] args) { Scanner input=new Scanner(System.in); int[] WordsCharsLetters = {0,1,2}; while(input.hasNext()) { String sentence=input.nextLine(); if(sentence!=null&&sentence.length()>0){ WordsCharsLetters[0] += calculateAndPrintChars(sentence)[0]; WordsCharsLetters[1] += calculateAndPrintChars(sentence)[1]; WordsCharsLetters[2] += calculateAndPrintChars(sentence)[2]; } else break; } input.close(); System.out.println("Words: " + WordsCharsLetters[0]); System.out.println("Characters: " + WordsCharsLetters[1]); System.out.println("Letters: " + WordsCharsLetters[2]); } static int[] calculateAndPrintChars(String sentence) { int[] WCL = new int[3]; String[] sentenceArray=sentence.split(" "); WCL[0] = sentenceArray.length; int letterCount=0; for(int i=0;i<sentence.length();i++) { if(Character.isLetter(sentence.charAt(i))) letterCount++; } WCL[1]...
import java.util.Random; import java.util.Scanner; public class Compass { // You will need to do the following:...
import java.util.Random; import java.util.Scanner; public class Compass { // You will need to do the following: // // 1.) Define a private instance variable which can // hold a reference to a Random object. // // 2.) Define a constructor which takes a seed value. // This seed will be used to initialize the // aforementioned Random instance variable. // // 3.) Define a static method named numberToDirection // which takes a direction number and returns a String // representing...
import java.util.Random; import java.util.Scanner; public class Compass { public Random r; public Compass(long seed){ r =...
import java.util.Random; import java.util.Scanner; public class Compass { public Random r; public Compass(long seed){ r = new Random(seed); }    public static String numberToDirection(int a){ if(a==0) return "North";    if(a==1) return "NorthEast"; if(a==2) return "East"; if(a==3) return "Southeast"; if(a==4) return "South"; if(a==5) return "Southwest"; if(a==6) return "West";    if(a==7) return "Northwest";    return "Invalid Direction" ; } public String randomDirection(){ return numberToDirection(r.nextInt()% 4 + 1); } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter seed: ");...
what i have: import java.util.Scanner; public class examples1 { public static void main(String[] args) { Square...
what i have: import java.util.Scanner; public class examples1 { public static void main(String[] args) { Square shade = new Square(getside()); System.out.println("Your chooses are:"); System.out.println("\nCircle"); System.out.println("Triangle"); System.out.println("Rectangle"); System.out.println("Square"); boolean moreShapes = true; boolean userChoice = true; while(moreShapes) { Scanner shapes = new Scanner (System.in); System.out.println("\nWhat shape do you want:"); String yourShape = shapes.nextLine(); if (userChoice = shade != null) { shade.getSide(); } System.out.println("\nWhat are two size paramters of the shape you choose:"); String yourParameter = shapes.nextLine(); System.out.println("\nYour shape is: " +...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public...
Can you fix the errors in this code? import java.util.Scanner; public class Errors6 {    public static void main(String[] args) {        System.out.println("This program will ask the user for three sets of two numbers and will calculate the average of each set.");        Scanner input = new Scanner(System.in);        int n1, n2;        System.out.print("Please enter the first number: ");        n1 = input.nextInt();        System.out.print("Please enter the second number: ");        n2 =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT