Flow chart to Java.

Hello! I was given a flow chart with no instructions on how to turn it to code. It's meant to be super basic because all we have really learned are scanners, strings, while, if, those kinds of things. I have been working on this for almost two days and keep striking out. I have included a screenshot of what I have figured out to so far.
5 Replies
JavaBot
JavaBot6d ago
This post has been reserved for your question.
Hey @SummerPsycho! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
TomiWebPro
TomiWebPro6d ago
maybe use elif bro also scanner not initalised
john
john6d ago
""" //name this file program2 or it will not work import java.util.Scanner;
public class program2 {
public static void main(String[] args) {
// Create a Scanner object to read input
Scanner scanner = new Scanner(System.in);

// Prompt the user for an input
System.out.print("Enter an amount of change (0-99): ");
int amount = scanner.nextInt();

// Calculate number of quarters
int quarters = amount / 25;
amount %= 25; // quarters is worth 25

// Calculate number of dimes
int dimes = amount / 10;
amount %= 10; // dimes is worth 10

// Calculate number of nickels
int nickels = amount / 5;
amount %= 5; // nickel is worth 5

//there may be remaining amount, here I add a nickel if there is
if (amount != 0){
nickels += 1;
}

// Display the result
System.out.println("Quarters: " + quarters);
System.out.println("Dimes: " + dimes);
System.out.println("Nickels: " + nickels);
}
}
public class program2 {
public static void main(String[] args) {
// Create a Scanner object to read input
Scanner scanner = new Scanner(System.in);

// Prompt the user for an input
System.out.print("Enter an amount of change (0-99): ");
int amount = scanner.nextInt();

// Calculate number of quarters
int quarters = amount / 25;
amount %= 25; // quarters is worth 25

// Calculate number of dimes
int dimes = amount / 10;
amount %= 10; // dimes is worth 10

// Calculate number of nickels
int nickels = amount / 5;
amount %= 5; // nickel is worth 5

//there may be remaining amount, here I add a nickel if there is
if (amount != 0){
nickels += 1;
}

// Display the result
System.out.println("Quarters: " + quarters);
System.out.println("Dimes: " + dimes);
System.out.println("Nickels: " + nickels);
}
}
"""
This message has been formatted automatically. You can disable this using /preferences.
TomiWebPro
TomiWebPro6d ago
For the zero to exit part you need input validation of different type (string vs int), not easy for your level, instead of "ZERO" maybe 0 (as in integer) and use a if statement would be the best, I overlooked this part when I was recreating your code, but it's easy to add
JavaBot
JavaBot6d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server