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...
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...
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
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
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
Write a JAVA program that prompts the user to enter a single name. Use a for...
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
​​​​​​​For java program. Write a while loop that will let the user enter a series of...
​​​​​​​For java program. Write a while loop that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates. for Loop Write a for loop to display all numbers from 13 - 93 inclusive, ending in 3. Write a for loop to display a string entered by the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT