mber of stars remaining. Use A loop. Please Write the code in Java and use the test ca
At a coffee shop , a coffee cost $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. Use A loop. Please Write the code in Java and use the test case examples as reference.
![### Test Case 12
**Prompt:** How many dollars will you spend?
**Input:** 25 [ENTER]
**Output:**
- Coffees: 29
- Stars remaining: 1
---
### Test Case 13
**Prompt:** How many dollars will you spend?
**Input:** 38 [ENTER]
**Output:**
- Coffees: 44
- Stars remaining: 2
---
### Test Case 14
**Prompt:** How many dollars will you spend?
**Input:** 50 [ENTER]
**Output:**
- Coffees: 58
- Stars remaining: 2
---
### Test Case 15
**Prompt:** How many dollars will you spend?
**Input:** 38654 [ENTER]
**Output:**
- Coffees: 45096
- Stars remaining: 2
---
These test cases demonstrate the relationship between dollars spent and the corresponding number of coffees and remaining stars in a hypothetical scenario.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F8c7c446f-cbb9-4516-a4dd-69b90c0496a4%2F0680255f-0323-480d-916a-22e61717cfad%2F1t7asfg_processed.png&w=3840&q=75)

Code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("How many Dollars will you spend?:");
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 remaining: " + stars);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images









