Question

In: Computer Science

TO DO in JAVA: The program that runs is TrackInsurance. Open this up and add five...

TO DO in JAVA: The program that runs is TrackInsurance. Open this up and add five instances of your ArtInsurance class at the noted location in the main method. Use whatever data you like.

TrackInsurance(below)

package itp120mod6;

import java.util.*;

public class TrackInsurance extends Object {

public static Scanner scan = new Scanner(System.in);

// method that runs first

public static void main(String[] args) throws Exception {

// make an ArrayList of customers and insurance policies

ArrayList cust = new ArrayList();

// note - the ArrayList below can hold Insurance objects

// but with inheritance, that includes Auto, Health, Life and Art

ArrayList ins = new ArrayList();

// create some fake customers (used for testing the program)

Customer c = new Customer("Duck", "Donald");

Customer c1 = new Customer("Mouse", "Minnie");

Customer c2 = new Customer("Mouse", "Mickey");

// add the customers to the array list

cust.add(c2);

cust.add(c1);

cust.add(c);

// make and add some insurance policies to the ArrayList

ins.add(new AutoInsurance(c, 2));

ins.add(new AutoInsurance(c1, 3));

/*ins.add(new HealthInsurance(c, 5));

ins.add(new HealthInsurance(c2, 1));

ins.add(new LifeInsurance(c, 30000, 65));

ins.add(new LifeInsurance(c1, 400000, 34));*/

// add your ArtInsurance instances here

//ins.add(new ArtInsurance(.....));

int choice = 0;

while (choice >= 0) {

choice = menu();

if (choice == 1)

printAllCustomers(cust);

else if (choice == 2)

printAllInsurance(ins);

else if (choice == 3) {

System.out

.println("Now lets find the information for a certain policy number");

System.out.println("What policy number do you want to find?");

int num = scan.nextInt();

printPolicy(ins, num);

} else if (choice == 4) {

System.out

.println("Now let's find all of the policies for a given customer");

System.out.println("What is the customer id?");

int custNum = scan.nextInt();

getCustomer(ins, custNum);

} else if (choice == 5)

sortCustNum(ins);

else if (choice == 6)

sortPolNum(ins);

else if (choice == 7) {

System.out.println("Bye!!!!!");

choice = -1;

}

} // end while

}

public static int menu() {

System.out.println("Choice:");

System.out

.println(" 1. Print all customers (call the toString method)");

System.out

.println(" 2. Print all insurance information (call the toString method)");

System.out

.println(" 3. Given a policy number, print the policy information");

System.out

.println(" 4. Find all of the policies for a given customer");

System.out

.println(" 5. Sort the insurance policy information by customer number");

System.out

.println(" 6. Sort the insurance policy information by policy number");

System.out.println(" 7. QUIT!! ");

System.out.println("\n CHOICE:");

int value = scan.nextInt();

return value;

}

// write a printAllCusts method that prints out the toString method for all

// of the customers

public static void printAllCustomers(ArrayList cust) {

}

// write a printAllInsurance method that prints out the toString method for

// all of the insurance policies

public static void printAllInsurance(ArrayList insure) {

// print out all of the information

for (Insurance ins : insure)

System.out.println(ins.toString());

}

// write a printPolicy method that prints the information for the policy

// number

// passed in or the statement "That policy does not exist" if it is not

// present

public static void printPolicy(ArrayList insure, int num) {

}

// write a getCustomer method that prints the information for all of the

// policies for a given customer

// that customer number is passed in. If none, have it print

// "There are no policies for that customer"

public static void getCustomer(ArrayList insure, int num) {

}

// write a method that sorts the policies by policy number

// look at the example in the search_sort package

public static void sortPolNum(ArrayList insure) {

Collections.sort(insure);

}

// write a method that sorts the policies by customer number

// this one is tougher since you can not use the Collections.sort() method

// so you need to just slug out some code.

// Look at the bubble sort from the SortByHand in the search_sort package

// You will want to do something similar

// Here is some pseudocode to help

//

public static void sortCustNum(ArrayList insure) {

{

for (int out = insure.size() - 1; out > 1; out--)

for (int in = 0; in < out; in++) {

// get the first insurance policy

// get the customer from that insurance policy

// get the customer number from that insurance policy

// get the second insurance policy

// get the customer from that insurance policy

// get the customer number from that insurance policy

// We want to check to see if the second customer number is

// less than the first one

// NOTE: When comparing customer numbers:

// SortByHand uses Strings so it uses the compareTo()

// method.

// We are comparing integers so we can just use <

// if the second customer number is less than the first one

// swap the two insurance policies in the original "insure"

// ArrayList

// check out the SortByHand to see how to swap.

}

}

}

}

------------------------------------------------------------------------------------------------------------------------------------------

public class ArtInsurance extends Insurance {

//variables

private String description;

private double value;

//constructor which internally calls the super class constructoor which sets values to super class variables as well

public ArtInsurance(Customer cust, String description, double value,int policyNum,double yearlyRate) {

super(cust,policyNum,yearlyRate);

this.description = description;

this.value = value;

}

//constructor

public ArtInsurance(String description, double value) {

super();

this.description = description;

this.value = value;

}

//getters and setters

public String getDescription() {

return description;

}

public void setDescription(String description) {

this.description = description;

}

public double getValue() {

return value;

}

public void setValue(double value) {

this.value = value;

}

@Override

public void calcRate() {

// TODO Auto-generated method stub

yearlyRate=0.6;

}

//toString()

@Override

public String toString() {

return "ArtInsurance [description=" + description + ", value=" + value

+ ", customer=" + customer + ", yearlyRate=" + yearlyRate

+ ", policyNumber=" + policyNumber + "]";

}

}

Solutions

Expert Solution

Modified Main Method:

import java.util.*;

public class TrackInsurance extends Object {

public static Scanner scan = new Scanner(System.in);

// method that runs first

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {

// make an ArrayList of customers and insurance policies

ArrayList cust = new ArrayList();

// note - the ArrayList below can hold Insurance objects

// but with inheritance, that includes Auto, Health, Life and Art

ArrayList ins = new ArrayList();

// create some fake customers (used for testing the program)

Customer c = new Customer("Duck", "Donald");

Customer c1 = new Customer("Mouse", "Minnie");

Customer c2 = new Customer("Mouse", "Mickey");

// add the customers to the array list

cust.add(c2);

cust.add(c1);

cust.add(c);

// make and add some insurance policies to the ArrayList

ins.add(new AutoInsurance(c, 2));

ins.add(new AutoInsurance(c1, 3));

/*ins.add(new HealthInsurance(c, 5));

ins.add(new HealthInsurance(c2, 1));

ins.add(new LifeInsurance(c, 30000, 65));

ins.add(new LifeInsurance(c1, 400000, 34));*/

// add your ArtInsurance instances here

//ins.add(new ArtInsurance(.....));
//here I have type casted to object to avoid errors since ArrayList is not generic
ins.add((Object) new ArtInsurance(c, "Painting",5000,123,85));
ins.add((Object) new ArtInsurance(c1, "Drawing",5000,1234,85));
ins.add((Object) new ArtInsurance(c2, "MOnoArt",5000,12345,85));
ins.add((Object) new ArtInsurance(c2, "ArtisticPainting",5000,123456,85));
ins.add((Object) new ArtInsurance(c1, "WetPainting",5000,123789,85));

int choice = 0;

while (choice >= 0) {

choice = menu();

if (choice == 1)

printAllCustomers(cust);

else if (choice == 2)

printAllInsurance(ins);

else if (choice == 3) {

System.out

.println("Now lets find the information for a certain policy number");

System.out.println("What policy number do you want to find?");

int num = scan.nextInt();

printPolicy(ins, num);

} else if (choice == 4) {

System.out

.println("Now let's find all of the policies for a given customer");

System.out.println("What is the customer id?");

int custNum = scan.nextInt();

getCustomer(ins, custNum);

} else if (choice == 5)

sortCustNum(ins);

else if (choice == 6)

sortPolNum(ins);

else if (choice == 7) {

System.out.println("Bye!!!!!");

choice = -1;

}

} // end while

}

public static int menu() {

System.out.println("Choice:");

System.out

.println(" 1. Print all customers (call the toString method)");

System.out

.println(" 2. Print all insurance information (call the toString method)");

System.out

.println(" 3. Given a policy number, print the policy information");

System.out

.println(" 4. Find all of the policies for a given customer");

System.out

.println(" 5. Sort the insurance policy information by customer number");

System.out

.println(" 6. Sort the insurance policy information by policy number");

System.out.println(" 7. QUIT!! ");

System.out.println("\n CHOICE:");

int value = scan.nextInt();

return value;

}

// write a printAllCusts method that prints out the toString method for all

// of the customers

public static void printAllCustomers(ArrayList cust) {

}

// write a printAllInsurance method that prints out the toString method for

// all of the insurance policies

public static void printAllInsurance(ArrayList insure) {

// print out all of the information

for (Insurance ins : insure)

System.out.println(ins.toString());

}

// write a printPolicy method that prints the information for the policy

// number

// passed in or the statement "That policy does not exist" if it is not

// present

public static void printPolicy(ArrayList insure, int num) {

}

// write a getCustomer method that prints the information for all of the

// policies for a given customer

// that customer number is passed in. If none, have it print

// "There are no policies for that customer"

public static void getCustomer(ArrayList insure, int num) {

}

// write a method that sorts the policies by policy number

// look at the example in the search_sort package

public static void sortPolNum(ArrayList insure) {

Collections.sort(insure);

}

// write a method that sorts the policies by customer number

// this one is tougher since you can not use the Collections.sort() method

// so you need to just slug out some code.

// Look at the bubble sort from the SortByHand in the search_sort package

// You will want to do something similar

// Here is some pseudocode to help

//

public static void sortCustNum(ArrayList insure) {

{

for (int out = insure.size() - 1; out > 1; out--)

for (int in = 0; in < out; in++) {

// get the first insurance policy

// get the customer from that insurance policy

// get the customer number from that insurance policy

// get the second insurance policy

// get the customer from that insurance policy

// get the customer number from that insurance policy

// We want to check to see if the second customer number is

// less than the first one

// NOTE: When comparing customer numbers:

// SortByHand uses Strings so it uses the compareTo()

// method.

// We are comparing integers so we can just use <

// if the second customer number is less than the first one

// swap the two insurance policies in the original "insure"

// ArrayList

// check out the SortByHand to see how to swap.

}

}

}

}


Related Solutions

Given the following program(Java); we are asked to do the following 1. Add a loop in...
Given the following program(Java); we are asked to do the following 1. Add a loop in the main to enqueue 12 items of your choice. 2. Be sure to implement some form of error checking that lets you know if the loop tries to add too many items to the queue. Error message: "Unexpected overflow" 3. Add a loop to dequeue items and print them on their own line with their location. Location = ? item = ? package Khatrijavaarrayqueue;...
Make a java program of Mickey I have the starter program but I need to add...
Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it. import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; public class Mickey extends Canvas { public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); } public void paint(Graphics g) { Rectangle bb = new Rectangle(100, 100, 200, 200); mickey(g, bb); } public void...
Create a simple dice game in Java. Add screenshots and the program here.
Create a simple dice game in Java. Add screenshots and the program here.
Complete the attached program by adding the following: a) add the Java codes to complete the...
Complete the attached program by adding the following: a) add the Java codes to complete the constructors for Student class b) add the Java code to complete the findClassification() method c) create an object of Student and print out its info in main() method of StudentInfo class. * * @author * @CS206 HM#2 * @Description: * */ public class StudentInfo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application...
Write a Java program that will add the digits of a person’s birth date to obtain...
Write a Java program that will add the digits of a person’s birth date to obtain a single digit to generate a numerology number. Write one separate method for each of the following tasks (it goes w/o saying that you will have a main() method along with these): date validating date crunching First: Get a Date Numerology has been used since ancient times to shed light on relationships, health, and global events. Each element in a birth date is believed...
Write a program to perform the following actions: the language is Java – Open an output...
Write a program to perform the following actions: the language is Java – Open an output file named “Assign14Numbers.txt” – Using a do-while loop, prompt the user for and input a count of the number of random integers to produce, make sure the value is between 35 and 150, inclusive. – After obtaining a good count, use a for-loop to generate the random integers in the range 0 ... 99, inclusive, and output each to the file as it is...
Java Language Add a recursive method to the program shown in the previous section that states...
Java Language Add a recursive method to the program shown in the previous section that states how many nodes does the stack have. Code: class Stack { protected Node top; Stack() { top = null; } boolean isEmpty() { return( top == null); } void push(int v) { Node tempPointer; tempPointer = new Node(v); tempPointer.nextNode = top; top = tempPointer; } int pop() { int tempValue; tempValue = top.value; top = top.nextNode; return tempValue; } void printStack() { Node aPointer...
Java Language Add a recursive method to the program shown in the previous section that allows...
Java Language Add a recursive method to the program shown in the previous section that allows remove the last node from the stack. Code: class Stack { protected Node top; Stack() { top = null; } boolean isEmpty() { return( top == null); } void push(int v) { Node tempPointer; tempPointer = new Node(v); tempPointer.nextNode = top; top = tempPointer; } int pop() { int tempValue; tempValue = top.value; top = top.nextNode; return tempValue; } void printStack() { Node aPointer...
Java Language Add a recursive method to the program shown in the previous section that allows...
Java Language Add a recursive method to the program shown in the previous section that allows insert a value at the end of the stack. Code: class Stack { protected Node top; Stack() { top = null; } boolean isEmpty() { return( top == null); } void push(int v) { Node tempPointer; tempPointer = new Node(v); tempPointer.nextNode = top; top = tempPointer; } int pop() { int tempValue; tempValue = top.value; top = top.nextNode; return tempValue; } void printStack() {...
Writing a Modular Program in Java In this lab, you add the input and output statements...
Writing a Modular Program in Java In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31. Instructions Notice that variables have been declared for you....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT