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.

Expert's answer

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!

LATEST TUTORIALS
APPROVED BY CLIENTS