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 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.
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...
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...
What do you feel that you have gotten from this class? Was the class what you...
What do you feel that you have gotten from this class? Was the class what you expected? What new things about the subject of nutrition have you learned from this class (if anything)? How do you feel the information that you have learned will help you in your personal or professional life (if at all)? What information do you think that you will be most likely to share with others? Why? Nutrition class, 250 words or more. General about nutrition...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart or another diagramming tool. If you can’t find a diagramming tool, you can hand draw the diagram but make sure it is legible. Points to remember: • Include all classes on your diagram. There are nine of them. • Include all the properties and methods on your diagram. • Include the access modifiers on the diagram. + for public, - for private, ~ for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT