Question

In: Computer Science

Eclipse Exercise 1 Write a Java application that implements different types of insurance policies for employees...

Eclipse

Exercise 1

Write a Java application that implements different types of insurance policies for employees of an organization.

Let Insurance be an abstract superclass and Health and Life two of its subclasses that describe respectively health insurance and life insurance.

The Insurance class defines an instance variable of type String to describe the type of insurance and an instance variable of type double to hold the monthly cost of that insurance.

Implement the get methods for both variables of class Insurance. Declare also two abstract methods named setInsuranceCost() and displayInfo() for this class.

The Life and Health class should implement setInsuranceCost and display methods by setting the appropriate monthly fee and display the information for each insurance type.

Write a driver class to test this hierarchy. This application should ask the user to enter the type of insurance and its monthly fee. Then, will create the appropriate object (Life or Health) and display the insurance information.

As you create each insurance object, place an Insurance reference to each new Insurance object into an array. Each class has its own setInsuranceCost method. Write a polymorphic screen manager that walks through the array sending setInsuranceCost messages to each object in the array and displaying this information on the screen.

Exercise #2:

Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time).

Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour.

Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the user to choose game tester type and enter the number of hours for the part-time testers.

Exercise #3:

CityToronto bank provides mortgages for individuals and businesses up to $300,000. Write a Java application that keeps track of mortgages and computes the total amount owed at any time (mortgage amount + interest).

Design the following classes to implement your application:

Mortgage – an abstract class that implements the MortgageConstants interface. A Mortgage includes a mortgage number, customer name, amount of mortgage, interest rate, and term.

Don’t allow mortgage amounts over $300,000. Force any mortgage term that is not defined in the MortgageConstants interface to a short-term, one year loan. Create a getMortgageInfo method to display all the mortgage data.

MortgageConstants – includes constant values for short-term (one year), medium-term (three years) and long-term (5 years) mortgages. It also contains constants for bank name and the maximum mortgage amount.

BusinessMortgage – extends Mortgage. Its constructor sets the interest rate to 1% over the current prime rate.

PersonalMortgage - extends Mortgage. Its constructor sets the interest rate to 2% over the current prime rate.

ProcessMortgage – a main class that create an array of 3 mortgages. Prompt the user for the current interest rate. Then in a loop prompts the user for a mortgage type and all relevant information for that mortgage. Store the created Mortgage objects in the array. When data entry is complete, display all mortgages.

Solutions

Expert Solution

  • EXERCISE 1:

// CREATE A JAVA CLASS IN INTELLIJ OR ECLIPSE IDE AND NAME IT AS INSURANCE . MAKE SURE THEY ARE COMING UNDER A SAME PACKAGE.

import java.util.*;

abstract class Insurance

{

public String typeIns;

public double monthcost;

public String gettypeIns()

{

return typeIns;

}

public double getmonthcost()

{

return monthcost;

}

abstract void setInsuranceCost(String a,double b);

abstract void displayInfo();

} //Insurance class ends here

class Life extends Insurance

{

void SetInsuranceCost(String q,double b)

{

typeIns=q;

monthcost=b;

}

void displayInfo()

{

System.out.println("The insurance type is" + obj.gettypeIns() + "the monthly cost is" + obj.getmonthcost());

}

} //LIFE class ends here

class Health extends Insurance

{

void SetInsuranceCost(String r,double t)

{

typeIns=r;

monthcost=t;

}

void displayInfo()

{

System.out.println("The insurance type is" + ob.gettypeIns() + "the monthly cost is" + ob.getmonthcost());

}

} //HEALTH class ends here

import java.util.*;

class Mainclass

{

public static void main(String args[])

{

Scanner input=new Scanner(System.in);

System.out.println("Enter the insurance type LIFE / HEALTH");

string str=input.nextLine();

System.out.println("Enter the monthly cost");

double mon=input.nextDouble();

if(str.equals("LIFE"){

Life one=new Life();

one.SetInsuranceCost(str,mon);

one.displayInfo();}

if(str.equals("HEALTH"){

Health two=new Health();

two.SetInsuranceCost(str,mon);

two.displayInfo();}

} // MAINCLASS ENDS HERE . RUN THIS CLASS AND CHECK WHETHER THE HIERARCHY IS IMPLEMENTED CORRECTLY

  • EXERCISE 2:

abstract class GameTester

{

public String Name;

public String status;

abstract void Fulltime(); // declare only is possible in abstract methods. no implementation can be done as mentioned in question

abstract void Parttime();

}

class FullTime extends GameTester

{

String a=Name;

String b=status;

int h;

public FullTime(String e,String u,int h){

this.h=h;

a=e;

b=u;}

void Fulltime()

{

int sum=h*3000;

System.out.println("The salary for FULL time gamer+a+ "is"+sum);

}}

class PartTime extends GameTester

{

String a=Name;

String b=status;

int h;

public PartTime(String e,String u,int h){

this.h=h;

a=e;

b=u;}

void Parttime()

{

int tot=h*20;

System.out.println("The salary for PART time gamer+b+" is"+Tot);

}

}

class MainClass

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the Gamer Name");

String str1=sc.nextLine();

System.out.println("Enter the Gamer Type FULL/PART");

String str2=sc.nextLine();

System.out.println("Enter the salary");

int sal=sc.nextInt();

if(str2.equals("FULL"))

{

FullTime obj=new FullTime(str1,str2,sal);

obj.Fulltime();

}

else if(str2.equals("PART"))

{

PartTime ob=new PartTime(str1,str2,sal);

ob.Parttime();

}

}

}

  • EXERCISE 3:

abstract class Mortgage

{


Related Solutions

Develop a Java application which implements an application for a store chain that has three types...
Develop a Java application which implements an application for a store chain that has three types of stores which are Book, Music, and Movie stores. Your application should have an Item abstract class which should be extended by the Book and Multimedia classes. Item class has abstract priceAfterTax method, you need to implement this method in derived classes. Multimedia class is a superclass for Music and Movie classes. Your project should also include the IPromotion interface, which should be implemented...
Write a java application that implements ArrayStack in chapter 16 of your textbook.
Write a java application that implements ArrayStack in chapter 16 of your textbook. Your application should have two files: 1. ArrayStack.java: This file will have the implementation of your stack. 2. TestStack.java: This file will have the main method where you declare your stack object and test the different stack operations. In addition to the ArrayStack methods given in the book, you are to write a toString method. This will allow you to print the Stack object from main. You...
USING JAVA and NOTTT using BufferedReader or BufferedWriter Write an application that implements a simple text...
USING JAVA and NOTTT using BufferedReader or BufferedWriter Write an application that implements a simple text editor. Use a text field and a button to get the file. Read the entire file as characters and display it in a TextArea. The user will then be able to make changes in the text area. Use a Save button to get the contents of the text area and write that over the text in the original file. Hint: Read each line from...
An insurance company has been reviewing the performance of the different types of insurance policies it...
An insurance company has been reviewing the performance of the different types of insurance policies it sells. Looking at policies sold in 2018, the insurance company found that out of 850 car insurance policies sold, 322 had claims against them; and for the 924 home polices .sold, 260 had claims against them. i. Calculate a 95% confidence interval for the proportion of claims made against car insurance policies. ii. Calculate a 95% confidence interval for the proportion of claims made...
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
For this coding exercise, you need to create a new Java project in Eclipse and finish...
For this coding exercise, you need to create a new Java project in Eclipse and finish all the coding in Eclipse. Run and debug your Eclipse project to make sure it works. Then you can just copy and paste the java source code of each file from Eclipse into the answer area of the corresponding box below. The boxes will expand once you paste your code into them, so don’t worry about how it looks J All data members are...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20 unsorted numbers. You should initiate this array yourself and first output the array in its original order, then output the array after it has been sorted by the selection sort algorithm. Create a second Java Application that implements an Insertion sort algorithm to sort the same array. Again, output the array in its original order, then output the array after it has been sorted...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20...
Create a Java Application that implements a Selection sort algorithm to sort an array of 20 unsorted numbers. You should initiate this array yourself and first output the array in its original order, then output the array after it has been sorted by the selection sort algorithm.
What are the different types of insurance policies that you would recommend to protect personal risks?...
What are the different types of insurance policies that you would recommend to protect personal risks? Discuss the merits for each of the types of insurance policies.
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT