Question

Create an application to accept data for an array of five CertOfDeposit objects, and then display...

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

Homework Answers

Answer #1
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:

Know the answer?
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
Similar Questions
How do I make this: public class Country {     private String name;     private double area;     private...
How do I make this: public class Country {     private String name;     private double area;     private int population;     public Country(String name, double area, int population) {         this.name = name;         this.area = area;         this.population = population;     }     public double getPopulationDensity() {         return population / area;     }     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public double getArea() {         return area;     }     public void setArea(double area) {         this.area = area;     }     public int getPopulation()...
Write an application in which you declare an array of eight first names. Write a try...
Write an application in which you declare an array of eight first names. Write a try block in which you prompt the user for an integer and display the name in the requested position. Create a catch block that catches the potential ArrayIndexOutOfBoundsException thrown when the user enters a number that is out of range. The catch block also should display the error message Subscript out of range. import java.util.*; public class BadSubscriptCaught {    public static void main(String[] args)...
Write a pseudocode for the following java programs: public class Item {    private String name;...
Write a pseudocode for the following java programs: public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;    }    public void setCost(double cost) {...
Write an application that asks a user to enter an integer. Display a statement that indicates...
Write an application that asks a user to enter an integer. Display a statement that indicates whether the integer is even or odd. ------------------------------------------ import java.util.Scanner; class EvenOdd {     public static void main(String[] args) {         // Write your code here     }     public static boolean isEven(int number) {     } }
Utilize the code from last week Add a default, full, and copy constructor. Also add a...
Utilize the code from last week Add a default, full, and copy constructor. Also add a constructor that allows you to specify only the name of the video game with no high score or times played specified. Adjust your code to demonstrate use of all 4 constructors and output of the resulting objects. #include <iostream> #include <string> #include <iomanip> using namespace std; class VideoGame { private:     string name;     int highScore;     int numOfPlays; public:     VideoGame() {        ...
Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount...
Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method for the sale amount, calculate the sales tax as 5% of the sale amount. Also include a display method that displays a purchase’s details. Provided code: import java.util.*; public class CreatePurchase { public static void main(String[] args) { Scanner input = new Scanner(System.in); Purchase purch = new...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
Sort by the following (name, address, dependent and gender) of these and ask the user which...
Sort by the following (name, address, dependent and gender) of these and ask the user which field to sort by !. this mean the following java must sort by address if we need, by name , by dependent , and by gender it depend on the following java it must have an option which we need to sort. please i need your help now, you just add the sorting on the following java. // Use a custom comparator. import java.io.BufferedReader;...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...