In: Computer Science
Instructions
Create an application to accept data for an array of five CertOfDeposit objects, and then display the data.
import java.time.*;
public class CertOfDeposit {
private String certNum;
private String lastName;
private double balance;
private LocalDate issueDate;
private LocalDate maturityDate;
public CertOfDeposit(String num, String name, double bal, LocalDate
issue) {
}
public void setCertNum(String n) {
}
public void setName(String name) {
}
public void setBalance(double bal) {
}
public void issueDate(LocalDate date) {
}
public String getCertNum() {
}
public String getName() {
}
public double getBalance() {
}
public LocalDate getIssueDate() {
}
public LocalDate getMaturityDate() {
}
}
---------------------------------------------------------------------------------------------------------------
import java.util.*;
import java.time.*;
public class CertOfDepositArray {
public static void main(String[] args) {
// Write your code here
}
public static void display(CertOfDeposit cd, int num) {
System.out.pritnln(, "Certificate " + num +
"\nName: " + cd.getCertNum() + " " +
cd.getName() + " Balance: $" + cd.getBalance() +
"\nIssued: " + cd.getIssueDate() +
"\nMatures: " + cd.getMaturityDate()););
}
}
import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Scanner; class CertOfDeposit { private String certNum; private String lastName; private double balance; private LocalDate issueDate; private LocalDate maturityDate; public CertOfDeposit(String num, String name, double bal, LocalDate issue) { certNum = num; lastName = name; balance = bal; issueDate = issue; maturityDate = issueDate.plusYears(1); } public void setCertNum(String n) { certNum = n; } public void setName(String name) { lastName = name; } public void setBalance(double bal) { balance = bal; } public void issueDate(LocalDate date) { issueDate = date; } public String getCertNum() { return certNum; } public String getName() { return lastName; } public double getBalance() { return balance; } public LocalDate getIssueDate() { return issueDate; } public LocalDate getMaturityDate() { return maturityDate; } } public class CertOfDepositArray { public static void main(String[] args) { // Write your code here Scanner in = new Scanner(System.in); DateTimeFormatter dateformatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); CertOfDeposit certs[] = new CertOfDeposit[5]; for(int i=0; i<5; i++) { System.out.println("Enter certificate number: "); String num = in.nextLine(); System.out.println("Enter certificate name: "); String name = in.nextLine(); System.out.println("Enter balance: "); Double bal = Double.parseDouble(in.nextLine()); System.out.println("Enter issue date: "); LocalDate issueDate = LocalDate.parse(in.nextLine(), dateformatter); certs[i] = new CertOfDeposit(num, name, bal, issueDate); System.out.println(); } for(int i=0; i<5; i++) { display(certs[i], i+1); } in.close(); } public static void display(CertOfDeposit cd, int num) { System.out.println("Certificate " + num + "\nName: " + cd.getCertNum() + " " + cd.getName() + " Balance: $" + cd.getBalance() + "\nIssued: " + cd.getIssueDate() + "\nMatures: " + cd.getMaturityDate()); } }
Please upvote, as i have given the exact answer as asked in
question. Still in case of any issues in code, let me know in
comments. Thanks!