Hi!!
I am unable to update one of the variable called “wallet” in the following program.
Kindly help me with it.
public class Myshop {
String toyType;
double cost;
boolean iscurrent;
int minAge;
double wallet = 4500;
boolean buy = wallet >= cost;
public static void greetCustomer(String name){
System.out.println("Welcome to my Toy shop " + name + "!");
}
public double tax(){
return cost + cost * 0.5;
}
public void description(){
System.out.println("Toy Type: " + toyType + "\nPrice : Rs " + tax() + " (tax inc.) " + "\nElectric: " + iscurrent + "\nMinimal Age: " + minAge + "\n");
}
public Myshop(String toy, double price, boolean iselectric, int age ){
toyType = toy;
cost = price;
iscurrent = iselectric;
minAge = age;
}
public void bought(){
System.out.println("You bought " + toyType + " of Price Rs " + tax() + " (tax inc.)");
}
public void walletStatus(){
System.out.println("\nMoney in wallet: Rs " + wallet + "\nCost of Toy bought: Rs " + tax());
double updatedWallet = wallet - cost;
System.out.println("Money left after purchase: Rs " + updatedWallet);
wallet = updatedWallet;
}
public void canBuy(){
System.out.println("\nDo you have enough money to buy " + toyType + ": " + buy);
}
public static void main(String[] args){
Myshop doll = new Myshop("Animal Doll", 2000, false, 5);
Myshop car = new Myshop("Toy Car", 1500, true, 8);
Myshop ball = new Myshop("Football", 2000, false, 5);
greetCustomer("Aniket");
ball.walletStatus();
car.walletStatus();
}
}