Question

In: Computer Science

LAB2 PART 1 FOR THE DATA TYPE CLASS: If you do not have UML of class...

LAB2 PART 1
FOR THE DATA TYPE CLASS:
If you do not have UML of class Account_yourLastName, you should do that first

Basesd on the UML, provide the code of data type class Account_yourLastName to hold the information of an account with account number (String), name (String), balance (double), with no-argument constructor, parameter constructor

Also, define some methods to handle the tasks: open account, check current balance, deposit, withdraw, and print monthly statement. At the end of each task we have the output as below:

Task OPEN ACCOUNT

For example: account number is 1567794657, name Mary Lane, and start balance is 500

-display the output:

OPEN NEW ACCOUNT – JAMES SMITH BANK

Account Number: 1567794657

Name:Mary Lane
Balance:500.0

Task CHECK CURENT BALANCE - Display the output:

CHECK CURRENT BALANCE – JAMES SMITH BANK

Account Number: 1567794657

Name:Mary Lane
Current Balance:500.0

Task DEPOSIT -If deposit amount is 200 to above account, display the output:

DEPOSIT – JAMES SMITH BANK

Account Number: 1567794657

Name:Mary Lane
Balance:500.0

Deposit amount: 200.0

New Balance:700.0

Task WITHDRAW -If withdraw amount is 300, display the output:

WITHDRAW – JAMES SMITH BANK

Account Number: 1567794657

Name:Mary Lane
Balance:500.0

Withdraw: 300.00

New Balance: 400.0

Task PRINT MONTHLY STATEMENT - dIsplay the following output:

MONTHLY STATEMENT – JAMES SMITH BANK

Account Number: 1567794657

Name:Mary Lane
End Balance:700.0

FOR THE DRIVER CLASS: provide the pseudo-code or flowchart then write the code for the BankService_yourLastName to provide the application of a bank service. First, provide the following menu of tasks:

BankService_Smith.java

MAIN MENU – JAMES SMITH BANK

  1. Open new account

  2. Check current balance

  3. Deposit

  4. Withdraw

  5. Print monthly statement

0. Exit

If users select other task before opening account then, the program will display message box:“You should open account first”

Task 1: Open new account:
-After reading all information of the account entered from the keyboard to create an account-Create the object of the class Account
-then display the output by calling the method Create New Account

Task 2: Check current balance
-call the method Check Current Balance from data type class to display the output

Task 3: Deposit
-ask users for depoit amount, call the method deposit from data type class to display the output

Task 4: Withdraw
-ask users for withdraw amount, call the method withdraw of class Account_yourLastName

Task 5: Print monthly statement -print the monthly statement

EXIT
When users exit display the message box:

“Thank you. The application is terminating..”

Requirement:
-Get the output of the task Monthly Statement then paste it in the file with pseudo-code -write the comment on each part in both classes

COMPILE AND RUN THE PART1 TO GET THE OUTPUT

Solutions

Expert Solution

// Account.java

public class Account {

      

       // data fields

       private String account_number;

       private String name;

       private double balance;

      

       // default constructor

       public Account()

       {

             account_number = null;

             name = null;

             balance = 0;

       }

      

       // parameterized constructor

       public Account(String account_number, String name, double balance )

       {

             this.account_number = account_number;

             this.name = name;

             this.balance = balance;

       }

       // method to print the details of the new account created

       public void create_new_account()

       {

             System.out.println("Account Number: "+account_number);

             System.out.println("Name: "+name);

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

       }

      

       // method to print the details with the current balance

       public void check_current_balance()

       {

             System.out.println("Account Number: "+account_number);

             System.out.println("Name: "+name);

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

       }

      

       // method to deposit an amount in the account and print the details after depositing

       public void deposit(double amount)

       {

             // check if amount is non-negative

             if(amount >= 0)

             {

                    System.out.println("Account Number: "+account_number);

                    System.out.println("Name: "+name);

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

                    System.out.println("Deposit amount: "+amount);

                    balance += amount;

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

             }

             else

                    System.out.println("Deposit Amount cannot be negative");

       }

      

       // method to withdraw the amount from the account and display the details after withdrawing

       public void withdraw(double amount)

       {

             // check if amount is non-negative and there is enough balance

             if(amount >=0 && amount <=balance)

             {

                    System.out.println("Account Number: "+account_number);

                    System.out.println("Name: "+name);

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

                    System.out.println("Withdraw: "+amount);

                    balance -= amount;

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

             }

             else

                    System.out.println("Withdraw Amount cannot be negative or greater than current balance");

       }

      

       // method to print monthly statement of the account

       public void print_monthly_statement()

       {

             System.out.println("Account Number: "+account_number);

             System.out.println("Name: "+name);

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

       }

}

//end of Account.java

// BankService.java

import java.util.Scanner;

public class BankService {

       public static void main(String[] args) {

             Account account = null; // create a reference of Account class

             int choice;

             Scanner scan = new Scanner(System.in);

             String name, account_number;

             double balance, amount;

             // loop that continues till the user exits

             do

             {

                    System.out.println("MAIN MENU – JAMES SMITH BANK");

                    System.out.println("1. Open new account");

                    System.out.println("2. Check current balance");

                    System.out.println("3. Deposit");

                    System.out.println("4. Withdraw");

                    System.out.println("5. Print monthly statement");

                    System.out.println("0. Exit");

                    // input fo choice

                    System.out.print("Enter your choice(0-5) : ");

                    choice = scan.nextInt();

                    scan.nextLine();

                    System.out.println();

                    switch(choice)

                    {

                    case 1: // create a new account

                           System.out.println("OPEN NEW ACCOUNT – JAMES SMITH BANK");

                           System.out.print("Enter Account Number : ");

                           account_number = scan.nextLine();

                           System.out.print("Enter Name : ");

                           name = scan.nextLine();

                           System.out.print("Enter Balance : ");

                           balance = scan.nextDouble();

                           account = new Account(account_number, name, balance);

                           account.create_new_account();

                           break;

                   

                    case 2: // check the current balance

                           System.out.println("CHECK CURRENT BALANCE – JAMES SMITH BANK");

                           if(account != null) // check if account is created

                                 account.check_current_balance();

                           else

                                 System.out.println("You should open account first");

                           break;

                          

                    case 3: // deposit an amount in the account

                           System.out.println("DEPOSIT – JAMES SMITH BANK");

                           if(account != null) // check if account is created

                           {

                                 System.out.print("Enter deposit amount : ");

                                 amount = scan.nextDouble();

                                 scan.nextLine();

                                 account.deposit(amount);

                           }else

                                 System.out.println("You should open account first");

                           break;

                          

                    case 4: // withdraw an amount from the account

                           System.out.println("WITHDRAW – JAMES SMITH BANK");

                           if(account != null) // check if account is created

                           {

                                 System.out.print("Enter withdraw amount : ");

                                 amount = scan.nextDouble();

                                 scan.nextLine();

                                 account.withdraw(amount);

                           }else

                                 System.out.println("You should open account first");

                           break;

                    case 5: // display the monthly statement of the account

                           System.out.println("MONTHLY STATEMENT – JAMES SMITH BANK");

                           if(account != null) // check if account is created

                                 account.print_monthly_statement();

                           else

                                 System.out.println("You should open account first");

                           break;

                    case 0: // exit

                           break;

                    default: // wrong choice

                           System.out.println("Wrong choice");

                                

                    }

                    System.out.println();

                   

             }while(choice != 0);

            

             // print the terminating message

             System.out.println("Thank you. The application is terminating..");

             scan.close();

       }

}

//end of BankService.java

Output:


Related Solutions

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...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you need to define: 1a.) +setName(value:String):void 1b.) +setGPA(value:double):void 1c.) +setID(value: String):void 1d.) +getName(): String 1e.) +getLastName():String 2.) Working with constructors 2a.) +Student() : This is the default constuctor. For the Strings properties, initialize them to null. The order is String ID, String name, String lastName, and double GPA. 2b.) +Student(value:String) - This constructor receives just the ID. 2c.) +Student(value:String, var: String) - This constructor receives...
Draw UML diagram Define a class named Document that contains a member variable of type string...
Draw UML diagram Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a function named getText that returns the text field and a way to set this value. Next, define a class for Email that is derived from Document and that includes member variables for the sender , recipient , and title of an e-mail message. Implement appropriate accessor and mutator functions. The body of...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
Use the UML tool to draw a UML class diagrambased on the descriptions provided below....
Use the UML tool to draw a UML class diagrambased on the descriptions provided below.The diagram should be drawn with a UML toolIt should include all the classes listed below and use appropriate arrows to identify the class relationshipsEach class should include all the described attributes and operations but nothing elseEach constructor and method should include the described parameters and return types - no more and no lessPlease do one of the following in JavaDescriptions of a PriceBecause of the...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
Download the data type class named as MathOperation:(given below) Create the project of part 2 then...
Download the data type class named as MathOperation:(given below) Create the project of part 2 then add class as a data type class and class MathCalculator_yourLastName as a driver class with main() of part 2 a. Draw UML of class MathOperation (See the topic about UML at TIP FOR LAB on eCampus) b. Create the pseudo-code or draw flowchart of the main of a driver class based on the requirement listed below (see the topic about pseudo-code or flowchart at...
C++ 1. Start with a UML diagram of the class definition for the following problem defining...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called  Dog that contains instance data that represent the dog's name and age.   define the Dog constructor to accept and initialize instance data.   create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age).   Include a toString...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT