Question

In: Computer Science

Have to write a program in Java for an ATM however when compiling after enter w...

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;
      
}
   }
   }

Solutions

Expert Solution


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


Related Solutions

Write a java program that asks user to enter a set of positive integer values. When...
Write a java program that asks user to enter a set of positive integer values. When the user stops (think of sentinel value to stop), the program display the maximum value entered by the user. Your program should recognize if no value is entered without using counter.
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
Write a java program that does the following: a) The user will enter data such as...
Write a java program that does the following: a) The user will enter data such as client name and client balance. The user can stop inputting data by entering "stop". The program should store the user inputs as a data member of an array. The type of this array is a class named ClientData. Below the output should be displayed by the program. The parts in bold are inputs from the user and not hard coded in the program Client...
In java, write a program that asks the user to enter a character. Then pass the...
In java, write a program that asks the user to enter a character. Then pass the character to the following methods. isVowel() – returns true if the character is a vowel isConsonant() – returns true if the character is a consonant changeCase() – if the character is lower case then change it to upper case and if the character is in upper case then change it to lower case. (return type: char) Example output is given below: Enter a character...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
In java coding, write a program that will print out a representation of a “W” using...
In java coding, write a program that will print out a representation of a “W” using a character that a user provides.
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter...
[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter five floating point values from the keyboard (warning: you are not allowed to use arrays or sorting methods in this assignment - will result in zero credit if done!). Have the program display the five floating point values along with the minimum and maximum values, and average of the five values that were entered. Your program should be similar to (have outputted values be...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following options menu: "Welcome" 1. Deposit to account 2. Withdraw 3. Exit
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT