In: Computer Science
Have to write a program in Java for an ATM however when compiling after enter w nothing happens.
import java.util.Scanner;
public class ATMMain {
public static void main(String[] args) {
double Ibalance = 5000, usermoney, withdrawB,
depositD;
String userFname = "X";
String userLname = "X";
String w, d, e, c;
System.out.println("Welcome");
Scanner input = new Scanner(System.in);
System.out.println("Welcome" + " "
+ userFname + " " + userLname);
System.out.println("your current
balance" + " " + Ibalance);
System.out.println("Enter in w =
withdraw, d = deposit, c = check, or e = logout");
w = input.next();
d = input.next();
e = input.next();
c = input.next();
System.out.println("enter
amount");
usermoney =
input.nextDouble();
if(input.next() == w) {
System.out.println("How much do you want to
withdraw");
withdrawB = Ibalance -
usermoney;
System.out.println(withdrawB);
}
else if(input.next() == d) {
System.out.println("How much do you want to
deposit");
depositD = Ibalance +
usermoney;
System.out.println(depositD);
}
else if (input.next() == c) {
System.out.println(Ibalance);
}
else if (input.next() == e) {
System.out.println("logging out");
}
else {
System.out.println("invalid
input");
}
switch (input.next()) {
case "w":
System.out.println("w");
break;
case "d":
System.out.println("d");
break;
case "c":
System.out.println("c");
break;
case "e":
System.out.println("e");
break;
}
}
}
import java.util.Scanner;
public class ATMMain {
public static void main(String[] args) {
double Ibalance = 5000, usermoney,
withdrawB, depositD;
String userFname = "X";
String userLname = "X";
String w, d, e, c;
System.out.println("Welcome");
Scanner input = new
Scanner(System.in);
System.out.println("Welcome" + " "
+ userFname + " " + userLname);
System.out.println("your current
balance" + " " + Ibalance);
System.out.println("Enter in w =
withdraw, d = deposit, c = check, or e = logout");
w = input.next();
if (w.equalsIgnoreCase("w"))
{
System.out.println("How much do you want to withdraw");
usermoney =
input.nextDouble();
withdrawB =
Ibalance - usermoney;
System.out.println(withdrawB);
} else if (w.equalsIgnoreCase("d"))
{
System.out.println("How much do you want to deposit");
usermoney =
input.nextDouble();
depositD =
Ibalance + usermoney;
System.out.println(depositD);
} else if (w.equalsIgnoreCase("c"))
{
System.out.println(Ibalance);
} else if (w.equalsIgnoreCase("e"))
{
System.out.println("logging out");
} else {
System.out.println("invalid input");
}
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me