Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer in Java. 1. At the local supermarket, hotdogs are sold in packages contai

ID: 3682431 • Letter: A

Question

Answer in Java.

1.

At the local supermarket, hotdogs are sold in packages containing a dozen (12) dogs, and yet hotdog buns are sold in packages containing 8 buns. One question we can ask is this: given some number of packages of dogs and buns, how many hotdogs can we make (one dog per bun)? In this problem, you'll answer that question.

Here is a description of what your program should do. After that is a description of how you should write the program.

Ask the user for the number of hotdog packages purchased.

Ask the user for the number of hotdog bun packages purchased.

If there are leftover dogs or buns, display what is left over, and how many.

Display to the console the number of hotdogs you can make (one dog per bun) without

buying more dogs or buns.

For example, if you have 2 packages of dogs (24 dogs total), and 3 packages of buns (24 buns total), you can make 24 hotdogs, and nothing left over. But if you have 1 package of dogs, and 2 packages of buns, you can only make 12 hotdogs, but you will have 4 buns left over.

To solve this problem, you should write a function called hotdog(), which takes as input (e.g. function arguments):

The number of packages of dogs (12 dogs per package)

The number of packages of buns (8 buns per package)

Your hotdog() function should do the following steps:

Calculate how many complete hotdogs that can be made (1 dog per bun)

Calculate how many dogs or buns are left over (you can have zero leftovers)

If there are leftover dogs or buns, display (to the console) what is left over, and how

many (display nothing if there are no leftovers).

Return the number of complete hotdogs you can make.

In main(), you should write code that does the following:

Ask the user for the number of hotdog packages purchased.

Ask the user for the number of hotdog bun packages purchased.

Call the function hotdog(), providing the correct information, and storing the result

4. Display to the console the number of hotdogs you can make (one dog per bun) without buying more dogs or buns.

Here's an example of how the program could work:

Or this:

You should prepare 6 examples to demonstrate that your program works, as follows:

Two different examples where there is nothing left over

Two different examples where there are dogs left over, but no buns left over

Two different examples where there are buns left over, but no dogs.

You should prepare these in advance, so that you can judge whether your program gets the answers right! It is of course impossible to have dogs and buns left over at the same time.

Explanation / Answer

import java.util.Scanner;

class group{
public static void main(String ang[]){
Scanner data= new Scanner(System.in);
int hdognum, hbunnum;
// Read 1st number
System.out.println("Enter number of hot dog bag purchased");
hdognum=data.nextInt();
// Read 2nd number
System.out.println("Enter number of hot bun bag purchased r");
hbunnum=data.nextInt();

hdognum*=12;

hbunnum *=8;

if hdognum = hbunnum

system.out.println(“ Hurray no extra hod dogs or hot buns needed”)

Else if hdognum > hbunnum

{

int reqhbun = hdognum – hbunnum

system.out.println (“ more buns have to be purchased %d, reqhbun);

}

Else if hbunnum > hdognum

{

int reqhdog = hbunnum – hdognum

system.out.println (“ more buns have to be purchased %d, reqhdog);

}

}
}