Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help in java: You are a fundraising distributor who needs to to pre-sell a limited number of doughnut coupon books. Each buyer can buy

Need help in java: You are a fundraising distributor who needs to to pre-sell a limited number of doughnut coupon books. Each buyer can buy as many as 4 coupon books. No more than 100 coupon books can be sold. Implement a program called Fundraiser that prompts the user for the desired number of coupon books and then displays the number of remaining coupon books. Repeat until all coupon books have been sold, and then display the total number of buyers.

My code is working for the most part, I am having trouble when I enter a number over 4 my code recognizes that it is an invalid request but still calculates it into the remaining number of books left, (for example, if I try to request 5 books it prints invalid, but will minus 5 books from the remaining and I don't know how to get it to not calculate a request over 4). I also have another error handling my coupon book but I'm not sure where. This is my code so far:

public static void main(String[] args) {

// TODO Auto-generated method stub

//presell 100 coupon books

//prompt user for desired number of books

// display how many coupon books are left

// total number of buyers

final int MAX_BOOKS = 100;

int availableCouponBooks = MAX_BOOKS;

int buyers = 0, requested = 0;

Scanner console = new Scanner(System.in);

while (availableCouponBooks > 0)

{

System.out.print("Requested Coupon Books: ");

requested = console.nextInt();

if (requested >= 1 && requested <= availableCouponBooks && requested <= 4);

{

buyers ++;

availableCouponBooks = availableCouponBooks-requested;

System.out.println("Available Coupon Books: " + availableCouponBooks);

System.out.println("Number of buyers: " + buyers);

} if (requested > 4)

System.out.println("Invalid request, Try Again!");

{

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

Know how procedures protect an organization

Answered: 1 week ago

Question

Knowledge of process documentation (process flow charting)

Answered: 1 week ago