Create an application to accept data for an array of five CertOfDeposit objects, and then display the data.
Use these classes and this code template to solve the
problem:
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() {
}
}
and
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()););
}
}
Must be able to pass these tests:
Test 1:
101 Barnes 100.50 1 6 2018 102 Rodgers 200.75 2 12 2006 103 Stark 275.00 3 15 2007 104 Potts 700.34 5 23 2011 105 Banner 1005.56 8 4 2016 Test 2:
95 Wayne 123 9 8 1998 96 Allen 345.56 10 11 1999 97 Prince 67.50 11 14 1991 98 Gordon 789.67 12 31 1994 99 Jordan 600.66 7 7 1997
import java.util.*;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.lang.*;
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;
}
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 Main {
public static void main(String[] args) {
//creating Array of the class CertOfDeposit
CertOfDeposit[] cd = new CertOfDeposit[5];
//Getting The Input
for( int i = 0; i < 5;i++ ){
Scanner myObj = new Scanner(System.in); // Create a Scanner object
String certNum = myObj.nextLine();
String name = myObj.nextLine();
double bal = myObj.nextDouble();
int date = myObj.nextInt();
int month = myObj.nextInt();
int year = myObj.nextInt();
try{
LocalDate dateInstance = LocalDate.of(year, month, date);
cd[i] = new CertOfDeposit(certNum,name,bal,dateInstance);
}
catch(Exception e){ //If the date is not proper then current date will store in IssuedDate variable
LocalDate lt = LocalDate.now();
cd[i] = new CertOfDeposit(certNum,name,bal,lt);
}
}
// Function call to display values
for( int i = 0; i < 5;i++ ){
display(cd[i],new Integer(cd[i].getCertNum()));
}
}
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());
}
}
Output:
Get Answers For Free
Most questions answered within 1 hours.