Question

In: Computer Science

Need Java Code and UML Design for the following program: Use the Account class created above...

Need Java Code and UML Design for the following program:

Use the Account class created above to simulate an ATM machine. Create five accounts in an array with id 0, 1, ..., 4, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run (see below). You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, the ATM machine will not stop.

Sample run of the ATM machine is as follows: Enter an id to start transactions: 4

Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1 The balance is 100.0

Main menu
1: check balance 2: withdraw

3: deposit
4: exit
Enter a choice: 2
Enter an amount to withdraw: 3

Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1 The balance is 97.0

Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 3
Enter an amount to deposit: 10

Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1 The balance is 107.0

Main menu
1: check balance 2: withdraw
3: deposit
4: exit
Enter a choice: 4

Enter an id to start transactions:

Solutions

Expert Solution

Given below is the code for the question. Please do rate the answe if it helped. Thank you.

Account.java
---

public class Account {
   private int id;
   private double balance;
  
   public Account() {
       id = 0;
       balance = 0;
   }

  
   public int getId() {
       return id;
   }


   public double getBalance() {
       return balance;
   }


   public void setId(int id) {
       this.id = id;
   }

   public void setBalance(double balance) {
       this.balance = balance;
   }
  
   public void withdraw(double amt) {
       if(amt <= balance)
           balance = balance - amt;
   }
  
   public void deposit(double amt) {
       if(amt > 0)
           balance = balance + amt;
   }
}


ATM.java
---
import java.util.Scanner;

public class ATM {
   public static void main(String[] args) {
       Account[] acc = new Account[5];
       for(int i = 0; i < 5; i++) {
           acc[i] = new Account();
           acc[i].setId(i);
           acc[i].setBalance(100);
       }

       int id;
       double amount;
       Scanner input = new Scanner(System.in);
       int choice;

       while(true) {
           do {
               System.out.print("Enter an id (0-4) to start transactions: ");
               id = input.nextInt();
           }while(id < 0 || id > 4);

           do {
               System.out.println("Main menu");
               System.out.println("1: check balance");
               System.out.println("2: withdraw");
               System.out.println("3: deposit");
               System.out.println("4: exit");
               System.out.print("Enter a choice: ");
               choice = input.nextInt();

               switch(choice) {
                   case 1:
                       System.out.println("The balance is " + acc[id].getBalance());
                       break;
                   case 2:  
                       System.out.print("Enter an amount to withdraw: ");
                       amount = input.nextDouble();
                       acc[id].withdraw(amount);
                       break;
                   case 3:  
                       System.out.print("Enter an amount to deposit: ");
                       amount = input.nextDouble();
                       acc[id].deposit(amount);
                       break;
                   case 4:
                       break;
                   default:
                       System.out.println("Invalid menu choice!");
               }
           }while(choice != 4);
       }
   }
}

output
----
Enter an id (0-4) to start transactions: 4
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1
The balance is 100.0
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 2
Enter an amount to withdraw: 3
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1
The balance is 97.0
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 3
Enter an amount to deposit: 10
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1
The balance is 107.0
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 4
Enter an id (0-4) to start transactions:


Related Solutions

Question(Design Java Method). There is a java code what created a "Student" class and hold all...
Question(Design Java Method). There is a java code what created a "Student" class and hold all the books owned by the student in the inner class "Book". Please propose a new method for the Student class so that given a Student object "student", a program can find out the title of a book for which student.hasBook(isbn) returns true. Show the method code and the calls to it from a test program. The Student class is following: import java.lang.Integer; import java.util.ArrayList;...
Design a class named Account (put it in a package named accountspackages) with the following UML...
Design a class named Account (put it in a package named accountspackages) with the following UML diagram: Account -customerID: int -customerName: String -balance: double +setCustomerID(int): void +setCustomerName(String): void +setBalance(double):void +getCustomerID(): int +getCustomerName(): String +getBalance(): double +deposit(double): void +withdraw(double): void +printInformation():void The method withdraw(double) withdraws a specified amount from the account if the amount is less than or equal the balance, otherwise the method prints the message: Sorry! The account does not have sufficient funds. The method printInformation() prints:     the...
What are the Signature lines of a Java class code? With an example. and the UML...
What are the Signature lines of a Java class code? With an example. and the UML diagram.
c++ The above Account class was created to model a bank account. An account has the...
c++ The above Account class was created to model a bank account. An account has the properties (keep the properties private) account number, balance, and annual interest rate, date created, and functions to deposit and withdraw. Create two derived classes for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn. Define a constant virtual toString() function in the Account class and override it in the derived classes to return the account...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task>...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task> list;//make private array public ToDoList() { //this keyword refers to the current object in a method or constructor this.list = new ArrayList<>(); } public Task[] getSortedList() { Task[] sortedList = new Task[this.list.size()];//.size: gives he number of elements contained in the array //fills array with given values by using a for loop for (int i = 0; i < this.list.size(); i++) { sortedList[i] = this.list.get(i);...
Java: Translate the Student class from the code provided to UML, e.g., -----------------------------_ | Student |...
Java: Translate the Student class from the code provided to UML, e.g., -----------------------------_ | Student | ------------------------------ | -lastName: String | | -firstName: String | ----------------------------- Java Code: public class Student { private String lName; private String fName; private int age; private double gpa; public Student(String lname, String fname, int age, double gpa);    public String lname();    public String fname();    public int age(); public double gpa(); public String toString()      {          return lName+ " " + fName+...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main {...
I need this Java code transform to Python Code PROGRAM: import java.util.Scanner; public class Main { static int count=0; int calculate(int row, int column) { count++; if(row==1&&column==1) { return 0; } else if(column==1) { return ((200+calculate(row-1,column))/2); } else if(column==row) { return (200+calculate(row-1,column-1))/2; } else { return ((200+calculate(row-1,column-1))/2)+((200+calculate(row-1,column))/2); }    } public static void main(String[] args) { int row,column,weight; Main m=new Main(); System.out.println("Welcome to the Human pyramid. Select a row column combination and i will tell you how much weight the...
**Java** - Creating from scratch. Original code hasn't been created yet. Design a class named Octagon...
**Java** - Creating from scratch. Original code hasn't been created yet. Design a class named Octagon that extends GeometricObject class and implements the Comparable and Cloneable interface. Assume that all eight sides of the octagon are of equal size. The area can be computed using following formula: Write a test program that creates an Octagon object with side values 5 and display its area and perimeter. Create a new object using clone method and compare the two objects using compareTo...
Part 1 Understand the Problem and Class Design with UML The client needs a program to...
Part 1 Understand the Problem and Class Design with UML The client needs a program to calculate the age of a tuna fish. The program must store the length of the fish in cm, and the weight of the fish in pounds. To calculate the estimated age of the fish in years multiply the length times the weight then divide by 10000. Design a class based on this word problem. Testing values are 300 cm length, and 1111.12 pounds. Using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT