Question: TO DO in JAVA: Add a class called ArtInsurance that inherits from Insurance. Look at the other three classes as a pattern. ArtInsurance should have

TO DO in JAVA: Add a class called ArtInsurance that inherits from Insurance. Look at the other three classes as a pattern. ArtInsurance should have new fields of String description (describes the art work) and double value (the value of the art work that you are insuring). Make certain your toString method prints these out. You can use whatever calcRate() calculation that you like for ArtInsurance.

Insurance (below)

package itp120mod6;

import java.text.*;

// note that this is an abstract class (see p455 of your text)

// I do not want any one to create a generic Insurance instance

// (we only sell Auto, Life, and Health) but so as not to repeat

// common fields in those , we move them up one hierarchy level

// and make a generic Inurance class

// implements the interface Comparable so I can define how to order

// or sort Insurance objects

public abstract class Insurance implements Comparable

{

// NOTE: these fields are protected!!!!! If I am to inherit

// these , they must be protected (private allows NO other classes

// to use them) - protected means this class and any class that inherits

// from this one can use these

protected Customer customer;

protected double yearlyRate;

protected int policyNumber;

// for currency output

NumberFormat currency = NumberFormat.getCurrencyInstance();

// a static variable used to make the insurance id unique

public static int num = 1000;

// full constructor - automatically creates a new Insurance id

public Insurance (Customer cust)

{

customer = cust;

policyNumber=num;

num++;

}

// used for reading from a file where policy number and rate already set

public Insurance (Customer cust, int polNum, double yrRate)

{

customer = cust;

policyNumber=polNum;

yearlyRate = yrRate;

}

// the empty constructor but still sets a unique id

public Insurance ()

{

policyNumber=num;

num++;

}

// the calcRate method is used to set the yearlyRate

// NOTE: this is an abstract class. That means it can not be used (has no body)

// but by putting here, we require any class that inherits from the Insurance class

// to fully implement this method if they want to be a concrete class

public abstract void calcRate();

// toString method. Note - we let the customer write themself out since they have their own toString method

// a class should only write out their fields in the toString method

public String toString ()

{

return (customer.toString() + " with policy number " + policyNumber + " has a yearly rate of " + currency.format(yearlyRate));

}

// getters and setters

public Customer getCustomer() {

return customer;

}

public int getPolicyNumber() {

return policyNumber;

}

public double getYearlyRate() {

return yearlyRate;

}

public void setCustomer(Customer customer) {

this.customer = customer;

}

public void setPolicyNumber(int policyNumber) {

this.policyNumber = policyNumber;

}

public void setYearlyRate(double yearlyRate) {

this.yearlyRate = yearlyRate;

}

// required by the Comparable interface. Describes how to compare two Insurance instances

// In this one, we want to compare policy numbers

// Look at how we did the one in the Customer blueprint

// Look at the one in the search_sort.Account class

// Note the difference if you are sorting on primitives versus objects

public int compareTo(Insurance ins)

{

// you get to write this!!

return -1;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!