510week2
Administrator
Administrator
发布于 2023-02-21 / 10 阅读 / 0 评论 / 0 点赞

510week2

Week 2 Session A Notes

-Chapter 6 Discussion (Intro to Classes)

-ATM Problem

Use Case Scenario (UML)

A screenshot of a cell phone  Description automatically generated

A close up of text on a white background  Description automatically generated

Class Diagram (UML)

A close up of a map  Description automatically generated A screenshot of a cell phone  Description automatically generated

Consider an Application sample run of actions

Automated Teller Machine

Choose 1 for Withdraw

Choose 2 for Deposit

Choose 3 for Check Balance

Choose 4 for EXIT

Choose the operation you want to perform:1

Enter money to be withdrawn:2000

Please collect your money

Automated Teller Machine

Choose 1 for Withdraw

Choose 2 for Deposit

Choose 3 for Check Balance

Choose 4 for EXIT

Choose the operation you want to perform:3

Balance : 3000

Automated Teller Machine

Choose 1 for Withdraw

Choose 2 for Deposit

Choose 3 for Check Balance

Choose 4 for EXIT

Choose the operation you want to perform:4

Coding Logic

import java.util.Scanner;

public class BANKATM {

public static void main(String args[]) {

​ double balance = 5000, withdraw, deposit;

​ Scanner s = new Scanner(System.*in*);

​ while(true) {

​ System.*out*.println("Automated Teller Machine");

​ System.*out*.println("Choose 1 for Withdraw");

​ System.*out*.println("Choose 2 for Deposit");

​ System.*out*.println("Choose 3 for Check Balance");

​ System.*out*.println("Choose 4 for EXIT");

​ System.*out*.print("Choose the operation you want to perform: ");

​ int n = s.nextInt();

​ switch(n) {

​ case 1:

​ System.*out*.print("Enter money to be withdrawn:");

​ withdraw = s.nextInt();

​ if(balance >= withdraw) {

​ balance = balance - withdraw;

​ System.*out*.println("Please collect your money");

​ }

​ else

​ System.*out*.println("Insufficient Balance");

​ System.*out*.println("");

​ break;

​ case 2:

​ System.*out*.print("Enter money to be deposited:");

​ deposit = s.nextInt();

​ balance = balance + deposit;

​ System.*out*.println("Your Money has been successfully depsited");

​ System.*out*.println("");

​ break;

​ case 3:

​ System.*out*.println("Balance : "+balance);

​ System.*out*.println("");

​ break;

​ case 4:

​ System.exit(0);

​ s.close();

​ }

​ }

}

}

Further consideration

Make use of objects for program.

Include (declare) class ‘data’ variables, ‘data’ methods.

- Lab 1 overview

- Work Java Review 1 for discussion