In: Computer Science
B. Creation of Program Application (Development Task 1) This program should ask the following questions to determine the number of hotdogs and buns (with minimum number of leftovers) needed for the Annual Hotdog Eating contest:
Assumptions are as follows:
• Hotdogs come in packages of 10.
• Hotdog buns come in packages of 8.
1. The program application should have the following inputs:
• How many people will be competing in the contest?
• How many hotdogs will each person be able to eat?
2. The program application should have the following outputs:
• The minimum number of packages of hotdogs required.
• The minimum number of packages of hotdog buns required.
• The number of hotdogs that will be left over.
• The number of hotdog bunds that will be left over.
3.) Must handle keyboard buffering properly.
4.) Must display proper data formatting of arguments.
5.) Mathematical calculations must be correct
I am writing this in Java
Short Summary:
**************Please upvote the answer and appreciate our time.************
Source Code:
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();
}
}
Refer the following screenshots for code indentation:
Sample Run 1:
Sample Run 2:
**************************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
**************************************************************************************