Prof. Jiang ISM3230 HW4 Page 1 of1 Be sure to submit homework via Canvas, not em
ID: 3730975 • Letter: P
Question
Prof. Jiang ISM3230 HW4 Page 1 of1 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., HW4FirstNameLastName). There will be a penalty for not following this requirement. Homework 4 Objects and Classes (3 points) You are required to create two classes, a Transaction class modeled after a banking situation and the main class (containing the main method). Please closely follow the requirements below Requirements for the Transaction class: A private data field named as date (of Date data type), representing the date of the transaction A private data field named as type (of char data type), representing the type of the transaction, such as "W" for withdrawal and "D" for deposit A private data field named as amount (of double data type), representing the amount of the transaction A private data field named as balance (of double data type), representing the balance of the account after the transaction A private data field named as description (of String data type), representing the description of the transaction A constructor that creates an instance of the Transaction class with specified values of transaction type, amount, balance, and description, and date of the transaction. Note: 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) Define the corresponding accessor (get) methods to access a transaction's date, type, amount description, and the balance, i.e., you need to define 5 get methods. Define a toString() method which does not receive parameters but returns a String that summarizes the transaction details, including transaction type, amount, balance after transaction, description of the transaction, and transaction date. You can organize and format the returned String in your own way, but you must include all of the required information. . . Note: the purpose of the Transaction class is to document a banking transaction, i.e., when a transaction happens, you can use the transaction parameters to create an instance of the Transaction class. Requirements for the main class To test the Transaction class, in the main method of your main class you need to do the following Create two instances of the Transaction class that represent the following transactions: transaction 1: type: deposit; amount: 50; balance: 1050; description: babysitting income transaction 2: type: withdraw; amount: 30; balance: 1020; description: tennis fee o o Call the toString method of the Transaction class to print out a summary of each transaction. . Check the rubric on Canvas. Save your work before closing the project (especially if you can't compile it). After you have closed the project from the project tab in NetBeans, zip the NetBeans project folder and submit the zipped folder through Canvas. Note: you will need this Transaction class for HW5Explanation / Answer
TransactionTest.java
public class TransactionTest {
public static void main(String[] args) {
Transaction t1 = new Transaction('D', 50, 1050, "babysitting income");
Transaction t2 = new Transaction('W', 30, 1020, "tennies fee");
System.out.println(t1);
System.out.println(t2);
}
}
Transaction.java
import java.text.SimpleDateFormat;
import java.util.Date;
public class Transaction {
private Date date;
private char type;
private double amount, balance;
private String description;
public Transaction(char type, double amount, double balance, String description) {
this.type=type;
this.amount=amount;
this.balance=balance;
this.description=description;
this.date = new Date();
}
public Date getDate() {
return date;
}
public char getType() {
return type;
}
public double getAmount() {
return amount;
}
public double getBalance() {
return balance;
}
public String getDescription() {
return description;
}
public String toString() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
return "Transaction [amount=" + amount + ", balance=" + balance
+ ", date=" + sdf.format(date) + ", description=" + description + ", type="
+ type + "]";
}
}
Output:
Transaction [amount=50.0, balance=1050.0, date=2018/03/16 20:24:21, description=babysitting income, type=D]
Transaction [amount=30.0, balance=1020.0, date=2018/03/16 20:24:21, description=tennies fee, type=W]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.