The variables charge
and deduction1
cannot be resolved as variables. I have declared the type and assigned values to them however they cant be resolved.
Any help is appreciated.
Comments are written next to the unresolved variables
This program calculates a parking charge for an ` individual while taking into account pensioners, time and disablities
class parking
{
public static void main (String [] a)
{
all();
System.exit(0);
}
public static double local_l(){
Scanner scanner = new Scanner(System.in);
System.out.println("Do you live locally ? (Yes or No)");
String local;
double deduction1;
local = scanner.nextLine();
if (local.equals("Yes")){
deduction1 = 1.0;
return deduction1;
}
if (local.equals("No")){
deduction1 = 0;
return deduction1;
} else{
System.out.println("Invalid answer, please answer : Yes or No (exactly as written)");
}
return 0.0;
}
public static void calculation(){
Scanner scanner = new Scanner(System.in);
int hours;
double charge;
String disabled;
disabled = scanner.nextLine();
if (disabled.equals("Yes")){
System.out.println("Parking is free");
}
if (disabled.equals("No")){
hours = scanner.nextInt();
if (hours == 1){
charge = 1.00;
}
if (hours >=2 && hours <= 4){
charge = 4.00;
}
if (hours >=5 && hours <=6){
charge = 4.50;
}
if (hours >= 7 && hours <=8){
charge = 5.50;
}
}
}
public static double old_age_pensioner (double charge, double deduction1,double deduction2){
Scanner scanner = new Scanner(System.in);
String oap;
System.out.println("Are you an old age pensioner? ");
oap = scanner.nextLine();
if(oap.equals("Yes")){
deduction2 = 2.0;
return deduction2;
}
if (oap.equals("No")){
deduction2 = 0;
return deduction2;
} else {
System.out.println("Invalid answer, please answer : Yes or No (exactly as written");
}
double result;
result = charge - deduction1 - deduction2; **charge cannot be resolved to a
variable as well as deduction 1**
System.out.println("The parking charge is" + result);
return 0;
}
public static void all(){
calculation();
local_l();
old_age_pensioner( charge, deduction1);
}
}