Write a program that calls methods for each of the following mini problems from its main method. Us a single Scanner for the program declared in the class as private Static Scanner keyboard = new Scanner(System.in); You have three identical prizes to give away and a pool of 10 finalists. The finalists are assigned numbers from 1 to 10.  Write a method to randomly select the numbers of 3 finalists to receive a prize.  Make sure not to pick the same number twice.  For example, picking finalists 3, 6, 2 would be valid but picking 3, 3, 11 would be invalid because finalist number 3 is listed twice and 11 is not a valid finalist number.   For this problem you can insert the following line of code to generate a random number between 1 and 10: int num = (int) (Math.random() * 10) +1; Notes: This project uses random numbers in a loop.  You might wish to introduce the Random class instead of Math.random().    2. Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon.  We can redeem 6 coupons for one chocolate bar from the machine.  This means that once you have started buying chocolate bars from the machine, you always have some coupons. We would like to know how many chocolate bars can be eaten if we start with N dollars and always redeem coupons if we have enough for an additional chocolate bar. For example, with 6 dollars we could consume 7 chocolate bars after purchasing 6 bars giving us 6 coupons and then redeeming the 6 coupons for one bar.  This would leave us with one extra coupon.  For 11 dollars, we could have consumed 13 chocolate bars and still have one coupon left.  For 12 dollars, we could have consumed 14 chocolate bars and have two coupons left. Write a method that takes input for the value for N and outputs to the terminal how many chocolate bars we can eat and how many coupons we would have leftover.  Use a loop that continues to redeem coupons as long as there are enough to get at least one chocolate bar.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a program that calls methods for each of the following mini problems from its main method.

Us a single Scanner for the program declared in the class as
private Static Scanner keyboard = new Scanner(System.in);

  1. You have three identical prizes to give away and a pool of 10 finalists. The finalists are assigned numbers from 1 to 10.  Write a method to randomly select the numbers of 3 finalists to receive a prize.  Make sure not to pick the same number twice.  For example, picking finalists 3, 6, 2 would be valid but picking 3, 3, 11 would be invalid because finalist number 3 is listed twice and 11 is not a valid finalist number.   For this problem you can insert the following line of code to generate a random number between 1 and 10:
    int num = (int) (Math.random() * 10) +1;

    Notes: This project uses random numbers in a loop.  You might wish to introduce the Random class instead of Math.random(). 

 

2. Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon.  We can redeem 6 coupons for one chocolate bar from the machine.  This means that once you have started buying chocolate bars from the machine, you always have some coupons. We would like to know how many chocolate bars can be eaten if we start with N dollars and always redeem coupons if we have enough for an additional chocolate bar.

For example, with 6 dollars we could consume 7 chocolate bars after purchasing 6 bars giving us 6 coupons and then redeeming the 6 coupons for one bar.  This would leave us with one extra coupon.  For 11 dollars, we could have consumed 13 chocolate bars and still have one coupon left.  For 12 dollars, we could have consumed 14 chocolate bars and have two coupons left.

Write a method that takes input for the value for N and outputs to the terminal how many chocolate bars we can eat and how many coupons we would have leftover.  Use a loop that continues to redeem coupons as long as there are enough to get at least one chocolate bar.

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education