In: Computer Science
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();
}
}
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: