Question

In: Computer Science

JAVA The previous assignment for the semester project required that you submit a document that included...

JAVA

The previous assignment for the semester project required that you submit a document that included class diagram document that used UML notation. By now (if not sooner), you should have a good idea of what classes you will need to include in your Java Application.You may, in fact, had identified additional classes you need to implement. For this assignment, you are to write your classes that are required for your Java application (minimum of three).

Additionally, you will need to write test classes in order to test out the classes that can be used to test the functionality of your classes. These test classes should be maintained. For example, if you add a new method to one of your classes in a later part of the development of this Java app, you should account for this in your test classes. This will help verify that your classes still work!

The above information is generally what I am working on. In the long run I am making a Banking application complete with GUI, but for this assignment i just need coding for only some classes as stated above. One class named Account is obvious but the other two can just be what goes with the program. I just need it to be set up that the bank can take in the User's name and customer ID, and then that customer can choose to withdraw, deposit, transfer, or check balance. They can also choose to deposit or withdraw from checking or savings. There is also a loan account that they can check balance. Nothing too complex is needed here.

Solutions

Expert Solution

//I have done two classes named Account and TestAccount. Also added the functionality mentioned above. Kindly comment down below if you have any query.

import java.util.*;

public class Account{
   private String userName;
   private int custId;
   private double savingsBalance;
   private double loanBalance;
  
   public Account(String userName, int custId, double savingsBalance, double loanBalance){
       this.userName = userName;
       this.custId = custId;
       this.savingsBalance = savingsBalance;
       this.loanBalance = loanBalance;
   }
  
   public static Account authenticate(Account[] acc, String userName, int custId){
       for(Account a: acc){
           if(a.userName.equals(userName) && a.custId == custId)
               return a;
       }
       return null;
   }
  
   public void withdraw(double amount){
       if(amount <= savingsBalance){
           savingsBalance -= amount;
           System.out.println("Withdraw successful. Current balance: "+savingsBalance);
       }
       else{
           System.out.println("Withdraw amount exceeds the total balance in the account");
       }
   }
  
   public void deposit(double amount){
       savingsBalance += amount;
       System.out.println("Deposit successful. Current balance: "+savingsBalance);
   }
  
   public void transfer(double amount, Account obj){
       if(amount <= savingsBalance){
           savingsBalance -= amount;
           obj.savingsBalance += amount;
           System.out.println("Transfer Successful");
       }
       else{
           System.out.println("Tranfer amount exceeds your account balance");
       }
   }
  
   public double getBalance(){
       return savingsBalance;
   }
  
   public double checkLoanBalance(){
       return loanBalance;
   }
}
class TestAccount{
   public static void main(String[] args){
       Account acc[] = new Account[5]; /* For testing created 5 users*/
       acc[0] = new Account("Vishal",1,100000.00,100.00); /*Initializing user1*/
       acc[1] = new Account("Vicky",2,100000.00,100.00);   /*Initializing user2*/
       acc[2] = new Account("Vikash",3,100000.00,100.00);   /*Initializing user3*/
       acc[3] = new Account("Vishu",4,100000.00,100.00);   /*Initializing user4*/
       acc[4] = new Account("Vishal Sah",5,10000.00,100.00);  /*Initializing user5*/
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter User name: ");
       String userName = sc.nextLine();
       System.out.println("Enter customer Id: ");
       int id = sc.nextInt();
       Account a = Account.authenticate(acc,userName,id);
       if(a!=null){
           while(true){
               System.out.println("1. Withdraw\n"+
                               "2. Deposit\n"+
                               "3. Transfer\n"+
                               "4. Savings Balance\n"+
                               "5. Loan Balance\n"+
                               "6. Logout");
               int choice = sc.nextInt();
               switch(choice){
                   case 1:   System.out.println("Enter amount to withdraw: ");
                           double amount = sc.nextDouble();
                           a.withdraw(amount);
                           break;
                   case 2:   System.out.println("Enter amount to deposit: ");
                           amount = sc.nextDouble();
                           a.deposit(amount);
                           break;
                   case 3:   System.out.println("Enter customer Id to which you want to transfer: ");
                           id = sc.nextInt();
                           System.out.println("Enter the amount: ");
                           amount = sc.nextDouble();
                           a.transfer(amount,acc[id-1]);
                           break;
                   case 4: System.out.println("Current savingds acc balance: "+a.getBalance());
                           break;
                   case 5: System.out.println("Current loan acc balance: "+a.getBalance());
                           break;
                   case 6: System.exit(0);
                   default: System.out.println("Invalid input");
               }
                      
              
           }
       }
       else{
           System.out.println("Customer not found.");
       }
   }
}

//Screenshot of the output is attached below.



Related Solutions

Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …....
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …. Your Individual Macronutrient Requirements for: Total kcals, Protein, Fat, Carbohydrate & Fiber Completed Diet Report Complete the Report Questions Completing the Diet Report Once you have recorded your 3-day diet, . You can also access the website in the Diet Project Resources module in Canvas. Instructions on how to generate the Cronometer nutrition analysis report can be found in the Diet Project Resources module....
In order to submit this assignment, you will use this webform to upload a document file...
In order to submit this assignment, you will use this webform to upload a document file (.doc) or (.docx) with your answers. If you need to make a graph you may use a drawing program or sketch by hand. Report your source in APA or MLA format. Be sure that your responses model clear economic reasoning and addresses each of the following: What are the advantages and disadvantages of a fixed exchange rate? What are the advantages and disadvantages of...
In order to submit this assignment, you will use this webform to upload a document file...
In order to submit this assignment, you will use this webform to upload a document file (.doc) or (.docx) with your answers. If you need to make a graph you may use a drawing program or sketch by hand. Report your source in APA or MLA format. Be sure that your responses model clear economic reasoning and addresses each of the following: What is the effect of expansionary fiscal policy on unemployment and inflation? Go online and find an article...
In order to submit this assignment, you will use this webform to upload a document file...
In order to submit this assignment, you will use this webform to upload a document file (.doc) or (.docx) with your answers. You may use a drawing program or sketch by hand. Be sure that your responses model clear economic reasoning and addresses each of the following: 1.) Suppose if the price of a good is $12, the quantity demanded is 50 units; when the price is $10, the quantity demanded is 100 units. Use the midpoint approach to compute...
Java program In this assignment you are required to create a text parser in Java/C++. Given...
Java program In this assignment you are required to create a text parser in Java/C++. Given a input text file you need to parse it and answer a set of frequency related questions. Technical Requirement of Solution: You are required to do this ab initio (bare-bones from scratch). This means, your solution cannot use any library methods in Java except the ones listed below (or equivalent library functions in C++). String.split() and other String operations can be used wherever required....
Please do this in java program. In this assignment you are required to implement the Producer...
Please do this in java program. In this assignment you are required to implement the Producer Consumer Problem . Assume that there is only one Producer and there is only one Consumer. 1. The problem you will be solving is the bounded-buffer producer-consumer problem. You are required to implement this assignment in Java This buffer can hold a fixed number of items. This buffer needs to be a first-in first-out (FIFO) buffer. You should implement this as a Circular Buffer...
This course contains a Course Project, where you will be required to submit one draft of...
This course contains a Course Project, where you will be required to submit one draft of the project at the end of Week 5, and the final completed project at the end of Week 7. Using the financial statements for Celgene Corporation and Gilead Sciences, Inc., respectively, you will calculate and compare the financial ratios listed further down this document for the fiscal year ending 2015, and prepare your comments about the two companies' performances based on your ratio calculations....
For your task, provide responses to the following in a Word document and submit them: project...
For your task, provide responses to the following in a Word document and submit them: project name - Build an IT infrastructure for a medium size company that does accounting Explain why you selected this project Based on your project selection, explain what requirements and restrictions would be encountered Explain how you would go about constructing this project using an engineering approach
In this project, you are required to write the java program “IO.java” to implement integer operations...
In this project, you are required to write the java program “IO.java” to implement integer operations “+”, “−”, “*”. Specifically, your program reads operands from a file named “input.txt” (which will be manually placed under the directory of the program) as strings. Then your program converts strings to integers, and computes the addition, subtraction, and multiplication of the operands. Finally, your program creates a file named “output.txt” (under the directory of the program) and writes the results to the file....
You are to submit a final written report outlining the material introduced this 2020 summer semester....
You are to submit a final written report outlining the material introduced this 2020 summer semester. The typed report should be between 2 and 3 pages. The report should also include topics as outlined below:   Introduction to Computers Essential components of a computer Computer ethics Windows and Introduction to Office Introduction to MS Word Introduction to Excel Introduction to Access Introduction to PowerPoint The final report will be worth 20% of your overall course grade and will serve as your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT