Question

Be sure to submit homework via Canvas, not email. Ask questions via email or Canvas inbox. Late assignments will not be accepted. Important: please zip the complete NetBeans project file (not just the jar or .java file) before submitting to Canvas. If you just submit the jar or .java file, it will not be graded and if you later submit the NetBeans project it may be treated as a late submission. Please name the project after your name (e.g., HWSFirstNameLastName). There will be a penalty for not following this requirement. Homework 5 Objects and Classes (8 points) You are required to create a NetBeans project modeled after a banking situation. First, create the project named as HWSYourFirstNameLastName. Check to create the main class, which will create a package under Source Packages, named after your project name, and open the main class containing the main method. Next, copy and paste the Transaction class from your HW4 into this package using NetBeans Refactor feature. If not using Refactor, just copy and paste the Transaction class into this package, then open the Transaction class and update its first line of code by changing the package name to its current package name. For this project, you are required to create two classes other than the Transaction class: an Account class (whereas an account may incur multiple transactions) and the main class (containing the main method). Please closely follow the requirements below Requirements for the Account class: You need to create the Account class as an independent file in the same package of your main class. Class data fields: A private data field of int data type, representing the id of the account. A private data field of String data type, representing the name of the customer A private data field of double data type, representing the balance of the account. A private data field of double data type, representing the annual interest rate. Key assumptions: (1) all accounts created following this class construct share the same interest rate. (2) While the annual interest rate is a percentage, e. g., 4.5%, but for simplicity users will just enter the double number as 4.5 (not 0.045). Therefore, you, the code developer, need to divide the annual interest rate by 100 whenever you use it in a calculation A private data field of Date data type, representing the account creating date A private data field of ArrayList data type, representing a list of transactions for the account. Each element of this ArrayList must be an instance of the Transaction class defined in HW4 (the Transaction class has been copied into the current package) Class constructors: A no-arg constructor that creates a default account with default variable values. Another constructor that creates an instance of the Account class with specified values for account id name, and initial balance. Note: for both constructors, instead of passing a Date object to the constructor, you should use the new operator inside the body of the constructor to pass a new Date instance to the date data field (as we did for the Account class in class)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I dont have any transaction class information so i have created one of my choice with single description field.If you have transaction class you can change the setter in the withdraw and deposit methods

Account class:

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

public class Account {

private int accId;

private String custName;

private double accBalance;

private double interestRate;

private Date createdAt;

private List<Transaction> transList=new ArrayList<>();

public Account() {

accId=0;

custName="";

accBalance=0.0;

interestRate=0;

Date dt=new java.util.Date();

createdAt=dt;

}

public Account(int id,String name,double balance,double rate){

accBalance=balance;

accId=id;

custName=name;

interestRate=rate;

Date dt=new java.util.Date();

createdAt=dt;

}

public int getAccId() {

return accId;

}

public void setAccId(int accId) {

this.accId = accId;

}

public String getCustName() {

return custName;

}

public void setCustName(String custName) {

this.custName = custName;

}

public double getAccBalance() {

return accBalance;

}

public void setAccBalance(double accBalance) {

this.accBalance = accBalance;

}

public double getInterestRate() {

return interestRate;

}

public void setInterestRate(double interestRate) {

this.interestRate = interestRate;

}

public Date getCreatedAt() {

return createdAt;

}

public void setCreatedAt(Date createdAt) {

this.createdAt = createdAt;

}

public List<Transaction> getTransList() {

return transList;

}

public void setTransList(List<Transaction> transList) {

this.transList = transList;

}

public double getMonthlyInterest(){

double inteEarned=this.accBalance*(this.interestRate/1200);

return inteEarned;

}

public void withDraw(double amt){

this.accBalance=this.accBalance-amt;

Transaction t=new Transaction();

t.setDesc("withdrawn amount of "+amt+" from "+accId+" remaining balance is "+accBalance);

transList.add(t);

}

public void deposit(double amtDepo){

this.accBalance=this.accBalance+amtDepo;

Transaction t=new Transaction();

t.setDesc("deposited amount of "+amtDepo+" to "+accId+" new balance is "+accBalance);

transList.add(t);

}

}

Transaction class;

public class Transaction {

private String desc;

public String getDesc() {

return desc;

}

public void setDesc(String desc) {

this.desc = desc;

}

}

Tester class:

public class AccountTester {

public static void main(String[] args) {

// TODO Auto-generated method stub

Account acc=new Account(1122,"George", 1000,1.5);

acc.deposit(30);//depositing 30,40,50$

acc.deposit(40);

acc.deposit(50);

acc.withDraw(5);//withdrwaing 5,4,2$

acc.withDraw(4);

acc.withDraw(2);

System.out.println("Account summary");

System.out.println("------------------------");

System.out.println("Account holders name : "+acc.getCustName());

System.out.println("Annual interest rate : "+acc.getInterestRate());

System.out.println("Account Balance : "+acc.getAccBalance());

System.out.println("Monthly interest earned : "+acc.getMonthlyInterest());

System.out.println("Transactions done");

for(Transaction t:acc.getTransList()){

System.out.println(t.getDesc());

}

}

}

Expected output:

貝Console X «terminated> Accountlester [Java Application] C:\Program FilesUavarel .8.0-111\binjavaw.exe (Mar 20 Account summar

Add a comment
Know the answer?
Add Answer to:
Be sure to submit homework via Canvas, not email. Ask questions via email or Canvas inbox....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance...

    Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance must be in the main class, and the requirement of printing a list of transactions for only the ids used when the program runs(Detailed in the Additional simulation requirements) is extremely important! Thank you so very much! Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and the main class (with the main...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • Please submit a .cpp file or upload zip if you have more than one file before...

    Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...

  • I was wondering how do I add an event to the buttons for show an image...

    I was wondering how do I add an event to the buttons for show an image on the menu bar by using lamda? 5C Create a JavaFX project in Eclipse with a name like ex2 or exercise2. Use the default package application. If you want, you may refactor it. Use the default JavaFX class (a source file) named Main.java. Again, you may change the name of the source file (class file, eventually) by refactoring. Download the runnable JAR file named...

  • Visual C# Homework 2 You are to write a program which will create a class called...

    Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

  • I have the files set up in the write place. I am just confused on how...

    I have the files set up in the write place. I am just confused on how to use some of the desire methods to execute this code. // Copy text file and insert line numbers Create a NetBeans project named AddLineNumbers following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans project AddLineNumbers and before you attempt to execute your application download and/or copy the text...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT