(amateur highs chool Java coder here). Iv'e been working on this project, and Iv'e reached a problem I can't figure out. Here's what I need help with: (I'm trying to write a program that will determine if the driver is speeding, and if so which one of 3 tickets is suitable, and, how much money to deduct from the account) 1. How do I use the reduc variable in the if statement? I get an error when i Include it in the last if statement like this....
//variables
int sbanka = 400;
int speed = 60;
int speedlimit = 60;
int ticket1 = 100;
//logic
//Ticket 1
if(speed > speedlimit + 10) {
System.out.println("You will recieve the level 1 ticket");
boolean reduc = true;
}
else {
System.out.println("Your speed was fine.");
}
//bank account calculation for ticket 1
if(reduc == true && sbanka >-100) {
sbanka -= 100;
System.out.println("we will deduct 100 dollars from your checking account");
Here is the finished program. Thanks for the help.
package labs;
public class SpeedingTicket {
public static void main(String[] args) {
//variables
int speed = 50;
int speedlimit = 60;
String text = ("Your account balance is now ");
boolean reduc = false;
//tickets
int t1 = 100;
int t2 = 150;
int t3 = 200;
//Bank account
int sbanka = (400);
//logic
if(speed > speedlimit + 10) {
System.out.println("You are getting a level one ticket");
reduc = true;
}
else {
System.out.println("Your speed was fine.");
reduc = false;
}
if(reduc == true) {
System.out.println(text + (sbanka - t1));
}
if(speed > speedlimit + 20) {
System.out.println("you are getting a level two ticket");
reduc = true;
}
else {
System.out.println("Your speed was fine.");
reduc = false;
}
if(reduc == true) {
System.out.println(text + (sbanka - t2));
}
if(speed > speedlimit + 30) {
System.out.println("This is a serious offence, you are getting a level 3 ticket");
reduc = true;
}
else {
System.out.println("Your speed was fine.");
reduc = false;
}
if(reduc == true) {
System.out.println(text + (sbanka - t3));
}
}
}