This one is all Java, All the needed 7 classes are provided below
in
Programming Questions
•
8 months ago
Hello Friends, I'm stuck creating the rest of the Company Clients, any help??
Also I had to comment out Individual Client 005, because I just can't get it to create a null pointer in the array policies.
public
class
Policy{
public static int LATEST_COUNTER = 0;
float amount;
int policyNumber;
public Policy(){
amount = 0.0f;
policyNumber = 0;
policyNumber= ++LATEST_COUNTER;
}
public Policy( float am){
amount = am;
policyNumber= ++LATEST_COUNTER;
}
public boolean isExpired(){
if ( this .amount==0) return true ;
else return false ;
}
public void print(){
System.out.println( "Policy #"
+policyNumber+
" with amount $" +amount
);
}
}
public static int LATEST_COUNTER = 0;
float amount;
int policyNumber;
public Policy(){
amount = 0.0f;
policyNumber = 0;
policyNumber= ++LATEST_COUNTER;
}
public Policy( float am){
amount = am;
policyNumber= ++LATEST_COUNTER;
}
public boolean isExpired(){
if ( this .amount==0) return true ;
else return false ;
}
public void print(){
System.out.println( "Policy #"
+policyNumber+
" with amount $" +amount
);
}
}
public
class
DepreciablePolicy
extends
Policy{
static float rate;
public DepreciablePolicy( float am, float a){
super (am);
rate = a;
}
public float depreciate(){
this .amount = (amount)-(amount*rate);
return this .amount;
}
public void print(){
System.out.println( "DepreciablePolicy #"
+policyNumber+
" with amount $" + this .amount
+ " rate " +rate*100+ "%" );
}
}
static float rate;
public DepreciablePolicy( float am, float a){
super (am);
rate = a;
}
public float depreciate(){
this .amount = (amount)-(amount*rate);
return this .amount;
}
public void print(){
System.out.println( "DepreciablePolicy #"
+policyNumber+
" with amount $" + this .amount
+ " rate " +rate*100+ "%" );
}
}
import
java.util.*;
public class ExpirablePolicy extends Policy{
Date expiryDate;
public ExpirablePolicy( float am, Date expire){
super (am);
expiryDate = expire;
}
public void print(){
System.out.println( "ExpirablePolicy #" +policyNumber+
" with amount $" +amount+ " expires: " +expiryDate);
}
public boolean isExpired(){
if (expiryDate.before( new Date()) || amount<=0) {
//expire = true;
return true ;
}
else {
//expire = false;
return false ;
}
}
}
public class ExpirablePolicy extends Policy{
Date expiryDate;
public ExpirablePolicy( float am, Date expire){
super (am);
expiryDate = expire;
}
public void print(){
System.out.println( "ExpirablePolicy #" +policyNumber+
" with amount $" +amount+ " expires: " +expiryDate);
}
public boolean isExpired(){
if (expiryDate.before( new Date()) || amount<=0) {
//expire = true;
return true ;
}
else {
//expire = false;
return false ;
}
}
}
import
java.util.*;
public abstract class Client{
static int CLIENT_COUNTER = 0;
String name;
int id;
Policy[] policies;
int numPolicies;
float totCove;
float ra;
public Client(String n){
name = n;
id = CLIENT_COUNTER;
policies = new Policy[10];
numPolicies = 0;
}
abstract float makeClaim( int polNum);
public Policy openPolicyFor( float amt){
Policy po = new Policy(amt);
policies[numPolicies]= po;
CLIENT_COUNTER++;
numPolicies = CLIENT_COUNTER;
totCove = amt;
return po;
}
public DepreciablePolicy openPolicyFor( float amt, float a){
DepreciablePolicy dPo = new DepreciablePolicy(amt, a);
policies[numPolicies]= dPo;
ra=a;
CLIENT_COUNTER++;
numPolicies = CLIENT_COUNTER;
totCove += amt;
// policies[4].amount = 500;//amt-(amt*a);
return dPo;
}
public ExpirablePolicy openPolicyFor( float amt, Date expire){
ExpirablePolicy ePo = new ExpirablePolicy(amt, expire);
policies[numPolicies]=ePo;
CLIENT_COUNTER++;
numPolicies = CLIENT_COUNTER;
totCove += amt;
return ePo;
}
public float totalCoverage(Policy p){
totCove = p.amount + p.amount;
return totCove;
}
public void print(){
System.out.println( "Client: " + name + " with " + numPolicies + " policies" );
}
}
public abstract class Client{
static int CLIENT_COUNTER = 0;
String name;
int id;
Policy[] policies;
int numPolicies;
float totCove;
float ra;
public Client(String n){
name = n;
id = CLIENT_COUNTER;
policies = new Policy[10];
numPolicies = 0;
}
abstract float makeClaim( int polNum);
public Policy openPolicyFor( float amt){
Policy po = new Policy(amt);
policies[numPolicies]= po;
CLIENT_COUNTER++;
numPolicies = CLIENT_COUNTER;
totCove = amt;
return po;
}
public DepreciablePolicy openPolicyFor( float amt, float a){
DepreciablePolicy dPo = new DepreciablePolicy(amt, a);
policies[numPolicies]= dPo;
ra=a;
CLIENT_COUNTER++;
numPolicies = CLIENT_COUNTER;
totCove += amt;
// policies[4].amount = 500;//amt-(amt*a);
return dPo;
}
public ExpirablePolicy openPolicyFor( float amt, Date expire){
ExpirablePolicy ePo = new ExpirablePolicy(amt, expire);
policies[numPolicies]=ePo;
CLIENT_COUNTER++;
numPolicies = CLIENT_COUNTER;
totCove += amt;
return ePo;
}
public float totalCoverage(Policy p){
totCove = p.amount + p.amount;
return totCove;
}
public void print(){
System.out.println( "Client: " + name + " with " + numPolicies + " policies" );
}
}
public class IndividualClient extends Client{
public IndividualClient(String name){
super (name);
}
@Override
float makeClaim( int polNum) {
// TODO Auto-generated method stub
//if(polNum==numPolicies)
policies[1].amount = policies[1].amount -(100 * DepreciablePolicy.rate);
/* if(policies[polNum-1].amount==0)
return 0;
*/
if (!policies[polNum-1].isExpired())
return policies[polNum-1].amount;
else
return 0;
}
}
public class CompanyClient extends Client{
public CompanyClient(String name){
super (name);
}
@Override
float makeClaim( int polNum) {
// TODO Auto-generated method stub
//if(polNum==numPolicies)
policies[1].amount = policies[1].amount -(100 * DepreciablePolicy.rate);
if (!policies[polNum-1].isExpired())
return policies[polNum-1].amount;
else
return 0;
}
}
import
java.util.*;
public class ClientTestProgram {
public static void main(String args[]) {
// Create an individual client, open some policies and then make some claims
IndividualClient ic = new IndividualClient( "Bob B. Pins" );
ic.openPolicyFor(100);
ic.openPolicyFor(200, 0.10f);
ic.openPolicyFor(300, new GregorianCalendar(2025, 0, 2).getTime());
ic.openPolicyFor(400, new GregorianCalendar(1999, 5, 4).getTime());
Policy p = new Policy(500);
System.out.println( "Here are the Individual Client's policies:" );
System.out.println( "Policies:" );
for ( int i=0; i<ic.numPolicies; i++) {
System.out.print( " " );
ic.policies[i].print();
System.out.println();
}
System.out.println(ic.numPolicies);
System.out.println( "Making claims:" );
System.out.println( "Claim for policy 0001: " + ic.makeClaim(1));
System.out.println( "Claim for policy 0002: " + ic.makeClaim(2));
System.out.println( "Claim for policy 0003: " + ic.makeClaim(3));
System.out.println( "Claim for policy 0004: " + ic.makeClaim(4));
//System.out.println("Claim for policy 0005: " + ic.makeClaim(5));
System.out.println( "Here are the Individual Client's policies after claims:" );
System.out.println( "Policies:" );
for ( int i=0; i<ic.numPolicies; i++) {.out.print( " " );
ic.policies[i].print();
System.out.println();
}
// Create a company client, open some policies and then make some claims
CompanyClient cc = new CompanyClient( "The Pillow Factory" );
cc.openPolicyFor(1000);
cc.openPolicyFor(2000, 0f);
cc.openPolicyFor(3000, new GregorianCalendar(2025, 0, 2).getTime());
cc.openPolicyFor(4000, new GregorianCalendar(1999, 5, 4).getTime());
System.out.println( "\nHere are the Company Client's policies:" );
System.out.println( "Policies:" );
System.out.println(cc.numPolicies);
for ( int i=0; i<cc.numPolicies; i++) {
System.out.print( " " );
cc.policies[i].print();
System.out.println();
}
System.out.println( "Making claims:" );
System.out.println( "Claim for policy 0006: " + cc.makeClaim(6));
System.out.println(cc.policies[0].amount);
System.out.println( "Claim for policy 0007: " + cc.makeClaim(7));
//System.out.println("Claim for policy 0008: " + cc.makeClaim(8));
//System.out.println("Claim for policy 0009: " + cc.makeClaim(9));
System.out.println( "Claim for policy 0005: " + cc.makeClaim(5));
System.out.println( "Here are the Company Client's policies after claims:" );
System.out.println( "Policies:" );
for ( int i=0; i<cc.numPolicies; i++) {
System.out.print( " " );
//cc.policies[i].print();
System.out.println();
}
}
public class ClientTestProgram {
public static void main(String args[]) {
// Create an individual client, open some policies and then make some claims
IndividualClient ic = new IndividualClient( "Bob B. Pins" );
ic.openPolicyFor(100);
ic.openPolicyFor(200, 0.10f);
ic.openPolicyFor(300, new GregorianCalendar(2025, 0, 2).getTime());
ic.openPolicyFor(400, new GregorianCalendar(1999, 5, 4).getTime());
Policy p = new Policy(500);
System.out.println( "Here are the Individual Client's policies:" );
System.out.println( "Policies:" );
for ( int i=0; i<ic.numPolicies; i++) {
System.out.print( " " );
ic.policies[i].print();
System.out.println();
}
System.out.println(ic.numPolicies);
System.out.println( "Making claims:" );
System.out.println( "Claim for policy 0001: " + ic.makeClaim(1));
System.out.println( "Claim for policy 0002: " + ic.makeClaim(2));
System.out.println( "Claim for policy 0003: " + ic.makeClaim(3));
System.out.println( "Claim for policy 0004: " + ic.makeClaim(4));
//System.out.println("Claim for policy 0005: " + ic.makeClaim(5));
System.out.println( "Here are the Individual Client's policies after claims:" );
System.out.println( "Policies:" );
for ( int i=0; i<ic.numPolicies; i++) {.out.print( " " );
ic.policies[i].print();
System.out.println();
}
// Create a company client, open some policies and then make some claims
CompanyClient cc = new CompanyClient( "The Pillow Factory" );
cc.openPolicyFor(1000);
cc.openPolicyFor(2000, 0f);
cc.openPolicyFor(3000, new GregorianCalendar(2025, 0, 2).getTime());
cc.openPolicyFor(4000, new GregorianCalendar(1999, 5, 4).getTime());
System.out.println( "\nHere are the Company Client's policies:" );
System.out.println( "Policies:" );
System.out.println(cc.numPolicies);
for ( int i=0; i<cc.numPolicies; i++) {
System.out.print( " " );
cc.policies[i].print();
System.out.println();
}
System.out.println( "Making claims:" );
System.out.println( "Claim for policy 0006: " + cc.makeClaim(6));
System.out.println(cc.policies[0].amount);
System.out.println( "Claim for policy 0007: " + cc.makeClaim(7));
//System.out.println("Claim for policy 0008: " + cc.makeClaim(8));
//System.out.println("Claim for policy 0009: " + cc.makeClaim(9));
System.out.println( "Claim for policy 0005: " + cc.makeClaim(5));
System.out.println( "Here are the Company Client's policies after claims:" );
System.out.println( "Policies:" );
for ( int i=0; i<cc.numPolicies; i++) {
System.out.print( " " );
//cc.policies[i].print();
System.out.println();
}
}
}
1