Answer to Question #137133 in Java | JSP | JSF for Amy

Question #137133
At a coffee shop, a coffee costs $1. Each coffee you purchase, earns one star. Seven stars earns a free coffee. In turn, that free coffee earns another star. Ask the user how many dollars they will spend, then output the number of coffees that will be given and output the number of stars remaining.
1
Expert's answer
2020-10-06T23:36:29-0400
import java.util.Scanner;

public class Q {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Dollars:");
        int dollars = in.nextInt();
        int coffees = dollars;
        int stars = dollars;
        while (stars >= 7) {
            coffees += stars / 7;
            stars = (stars % 7) + (stars / 7);

        }
        System.out.println("Coffees: " + coffees);
        System.out.println("Stars: " + stars);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
07.10.20, 21:24

Dear Amy, please run the program in console.

Amy
07.10.20, 21:04

I typed in this exact thing and it does not print anything. All it does is let me type in the number and after that nothing happens and it just closes the program.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS