SlideShare a Scribd company logo
1 of 8
Download to read offline
Here is the Person Class Provided:
Use the following files:
Person.java
Here is the tester file:
InsruanceTester.java
I have done three of the methods i just need the last one public double monthly premium method
completed. Here is my code:
public class Person
{
private String name;
private String gender;
private int age;
/**
* Consructs a Person object
* @param name the name of the person
* @param gender the gender of the person either
* m for male or f for female
* @param age the age of the person
*/
public Person(String name, String gender, int age)
{
this.name = name;
this.gender = gender;
this.age = age;
}
/**
* gets the age of this Person
* @return the age of this Person
*/
public int getAge()
{
return age;
}
/**
* gets the gender of this Person
* @return the gender of this Person
*/
public String getGender()
{
return gender;
}
/**
* gets the name of this Person
* @return the name of this Person
*/
public String getName()
{
return name;
}
/**
* Increases the age of this Person by 1 year
*/
public void birthday()
{
age = age + 1;
}
}
/**
* Models an Insurance client
*/
public class Insurance
{
private Person client;
/**
* Constructs an Insurance object with the given Person
* @param p the Person for this Insurance
*/
public Insurance(Person p)
{
client = p;
}
public int clientAge(){
return client.getAge();
}
public String clientGender(){
return client.getGender();
}
public void incrementAge(){
client.birthday();
}
}
Solution
//Person.java
public class Person
{
private String name;
private String gender;
private int age;
/**
* Consructs a Person object
* @param name the name of the person
* @param gender the gender of the person either
* m for male or f for female
* @param age the age of the person
*/
public Person(String name, String gender, int age)
{
this.name = name;
this.gender = gender;
this.age = age;
}
/**
* gets the age of this Person
* @return the age of this Person
*/
public int getAge()
{
return age;
}
/**
* gets the gender of this Person
* @return the gender of this Person
*/
public String getGender()
{
return gender;
}
/**
* gets the name of this Person
* @return the name of this Person
*/
public String getName()
{
return name;
}
/**
* Increases the age of this Person by 1 year
*/
public void birthday()
{
age = age + 1;
}
}
--------------------------------------------------------------------------------------------------------------
/**
* Models an Insurance client
*/
public class Insurance
{
private Person client;
/**
* Constructs an Insurance object with the given Person
* @param p the Person for this Insurance
*/
public Insurance(Person p)
{
client = p;
}
public int clientAge(){
return client.getAge();
}
public String clientGender(){
return client.getGender();
}
public void incrementAge(){
client.birthday();
}
/**
* The method monthlyPremium that sets the insurance
* value based on gender and age
* */
public double monthlyPremium() {
double insurance=0;
//Checking if age of client object is <16
//return -1
if(client.getAge()<16)
{
insurance=-1;
return insurance;
}
//checking if client gender is m
if(client.getGender().equals("m"))
{
//check age and set insurance
if(client.getAge()<25)
insurance=85.50;
//age is between 25 and 85(exclusive)
if(client.getAge()>=25 && client.getAge()<85)
insurance=55.00;
//age is >=85
if(client.getAge()>=85)
insurance=92.00;
}
else
{
//check age and set insurance
if(client.getAge()<25)
insurance=79.25;
//age is between 25 and 85(exclusive)
if(client.getAge()>=25 && client.getAge()<85)
insurance=45.00;
//age is >=85
if(client.getAge()>=85)
insurance=90.00;
}
//return insurance
return insurance;
}//end of the monthlyPremium
}
--------------------------------------------------------------------------------------------------------------
/**
* Test the Insurance class
*/
//InsruanceTester.java
public class InsruanceTester
{
public static void main(String[] args)
{
//male 15
Insurance policy = new Insurance(
new Person("Carlos", "m", 15));
System.out.println("underage: " + policy.monthlyPremium());
System.out.println("Expected: -1.0");
//male 16
policy.incrementAge(); //increment to 16
System.out.println("male < 25: " + policy.monthlyPremium());
System.out.println("Expected: 85.5");
//male 25
policy = new Insurance(
new Person("Henry", "m", 25));
System.out.println("male 25 to 85: " + policy.monthlyPremium());
System.out.println("Expected: 55.0");
//male 85
policy = new Insurance(
new Person("Thong", "m", 85));
System.out.println("male 85: " + policy.monthlyPremium());
System.out.println("Expected: 92.0");
//female 15
policy = new Insurance(
new Person("Ashwanee", "f", 15));
System.out.println("underage: " + policy.monthlyPremium());
System.out.println("Expected: -1.0");
//female 16
policy.incrementAge();
System.out.println("female < 25: " + policy.monthlyPremium());
System.out.println("Expected: 79.25");
//female 25
policy = new Insurance(
new Person("Rebecca", "f", 25));
System.out.println("female 25 to 85: " + policy.monthlyPremium());
System.out.println("Expected: 45.0");
//female 85
policy = new Insurance(
new Person("Chen", "f", 85));
System.out.println("female 85: " + policy.monthlyPremium());
System.out.println("Expected: 90.0");
}
}
--------------------------------------------------------------------------------------------------------------
Sample Output:
underage: -1.0
Expected: -1.0
male < 25: 85.5
Expected: 85.5
male 25 to 85: 55.0
Expected: 55.0
male 85: 92.0
Expected: 92.0
underage: -1.0
Expected: -1.0
female < 25: 79.25
Expected: 79.25
female 25 to 85: 45.0
Expected: 45.0
female 85: 90.0
Expected: 90.0

More Related Content

Similar to Here is the Person Class ProvidedUse the following filesPerson.pdf

#include -string- #include -string- #include -vector- #include -iostre (1).pdf
#include -string- #include -string- #include -vector- #include -iostre (1).pdf#include -string- #include -string- #include -vector- #include -iostre (1).pdf
#include -string- #include -string- #include -vector- #include -iostre (1).pdf
ashiyanabakersandcon
 
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdfRepeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
arracollection
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
ssuser562afc1
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdf
anandshingavi23
 
Hello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdfHello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdf
barristeressaseren71
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
monicafrancis71118
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
aplolomedicalstoremr
 
can do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdfcan do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdf
akshpatil4
 
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
infantsuk
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
MaruMengesha
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
anwarsadath111
 

Similar to Here is the Person Class ProvidedUse the following filesPerson.pdf (20)

C# 3.5 Features
C# 3.5 FeaturesC# 3.5 Features
C# 3.5 Features
 
#include -string- #include -string- #include -vector- #include -iostre (1).pdf
#include -string- #include -string- #include -vector- #include -iostre (1).pdf#include -string- #include -string- #include -vector- #include -iostre (1).pdf
#include -string- #include -string- #include -vector- #include -iostre (1).pdf
 
Kotlin Data Model
Kotlin Data ModelKotlin Data Model
Kotlin Data Model
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Designing Immutability Data Flows in Ember
Designing Immutability Data Flows in EmberDesigning Immutability Data Flows in Ember
Designing Immutability Data Flows in Ember
 
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdfRepeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
Repeat Programming Project 2 in Chapter 5. This time, add the follow.pdf
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdf
 
Kotlin class
Kotlin classKotlin class
Kotlin class
 
Hello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdfHello. Im creating a class called Bill. I need to design the class.pdf
Hello. Im creating a class called Bill. I need to design the class.pdf
 
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docxcodeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
codeComprehensionorders.txtwomens sandals 1011 6 78.00 red 12.docx
 
Computer programming 2 -lesson 4
Computer programming 2  -lesson 4Computer programming 2  -lesson 4
Computer programming 2 -lesson 4
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
can do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdfcan do this in java please thanks in advance The code that y.pdf
can do this in java please thanks in advance The code that y.pdf
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
 
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docxmaJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
maJavaProjectFinalExam.classpathmaJavaProjectFinalExam.p.docx
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Mar-2021_L15...
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
Creating a Facebook Clone - Part X.pdf
Creating a Facebook Clone - Part X.pdfCreating a Facebook Clone - Part X.pdf
Creating a Facebook Clone - Part X.pdf
 

More from xlynettalampleyxc

what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdf
xlynettalampleyxc
 
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdfThe output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
xlynettalampleyxc
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
xlynettalampleyxc
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdf
xlynettalampleyxc
 
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdfSet up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
xlynettalampleyxc
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
xlynettalampleyxc
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdf
xlynettalampleyxc
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdf
xlynettalampleyxc
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
xlynettalampleyxc
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdf
xlynettalampleyxc
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
xlynettalampleyxc
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdf
xlynettalampleyxc
 

More from xlynettalampleyxc (20)

According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdfAccording to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
 
Write a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdfWrite a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdf
 
which represents the ground state for the N- ion i. w.ia ere sm.pdf
which represents the ground state for the N- ion  i. w.ia ere sm.pdfwhich represents the ground state for the N- ion  i. w.ia ere sm.pdf
which represents the ground state for the N- ion i. w.ia ere sm.pdf
 
what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdf
 
What is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdfWhat is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdf
 
WEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdfWEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdf
 
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdfTwo astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
 
The ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdfThe ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdf
 
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdfThe output should now look like this Row 1 sum 30 Row 2 sum.pdf
The output should now look like this Row 1 sum 30 Row 2 sum.pdf
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdf
 
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdfSet up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdf
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdf
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdf
 
Name three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdfName three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdf
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 

Here is the Person Class ProvidedUse the following filesPerson.pdf

  • 1. Here is the Person Class Provided: Use the following files: Person.java Here is the tester file: InsruanceTester.java I have done three of the methods i just need the last one public double monthly premium method completed. Here is my code: public class Person { private String name; private String gender; private int age; /** * Consructs a Person object * @param name the name of the person * @param gender the gender of the person either * m for male or f for female * @param age the age of the person */ public Person(String name, String gender, int age) { this.name = name; this.gender = gender; this.age = age; } /** * gets the age of this Person * @return the age of this Person */ public int getAge() { return age; }
  • 2. /** * gets the gender of this Person * @return the gender of this Person */ public String getGender() { return gender; } /** * gets the name of this Person * @return the name of this Person */ public String getName() { return name; } /** * Increases the age of this Person by 1 year */ public void birthday() { age = age + 1; } } /** * Models an Insurance client */ public class Insurance { private Person client; /** * Constructs an Insurance object with the given Person
  • 3. * @param p the Person for this Insurance */ public Insurance(Person p) { client = p; } public int clientAge(){ return client.getAge(); } public String clientGender(){ return client.getGender(); } public void incrementAge(){ client.birthday(); } } Solution //Person.java public class Person { private String name; private String gender; private int age; /** * Consructs a Person object * @param name the name of the person * @param gender the gender of the person either * m for male or f for female * @param age the age of the person */ public Person(String name, String gender, int age) { this.name = name; this.gender = gender;
  • 4. this.age = age; } /** * gets the age of this Person * @return the age of this Person */ public int getAge() { return age; } /** * gets the gender of this Person * @return the gender of this Person */ public String getGender() { return gender; } /** * gets the name of this Person * @return the name of this Person */ public String getName() { return name; } /** * Increases the age of this Person by 1 year */ public void birthday() { age = age + 1; } } --------------------------------------------------------------------------------------------------------------
  • 5. /** * Models an Insurance client */ public class Insurance { private Person client; /** * Constructs an Insurance object with the given Person * @param p the Person for this Insurance */ public Insurance(Person p) { client = p; } public int clientAge(){ return client.getAge(); } public String clientGender(){ return client.getGender(); } public void incrementAge(){ client.birthday(); } /** * The method monthlyPremium that sets the insurance * value based on gender and age * */ public double monthlyPremium() { double insurance=0; //Checking if age of client object is <16 //return -1 if(client.getAge()<16) { insurance=-1;
  • 6. return insurance; } //checking if client gender is m if(client.getGender().equals("m")) { //check age and set insurance if(client.getAge()<25) insurance=85.50; //age is between 25 and 85(exclusive) if(client.getAge()>=25 && client.getAge()<85) insurance=55.00; //age is >=85 if(client.getAge()>=85) insurance=92.00; } else { //check age and set insurance if(client.getAge()<25) insurance=79.25; //age is between 25 and 85(exclusive) if(client.getAge()>=25 && client.getAge()<85) insurance=45.00; //age is >=85 if(client.getAge()>=85) insurance=90.00; } //return insurance return insurance; }//end of the monthlyPremium } --------------------------------------------------------------------------------------------------------------
  • 7. /** * Test the Insurance class */ //InsruanceTester.java public class InsruanceTester { public static void main(String[] args) { //male 15 Insurance policy = new Insurance( new Person("Carlos", "m", 15)); System.out.println("underage: " + policy.monthlyPremium()); System.out.println("Expected: -1.0"); //male 16 policy.incrementAge(); //increment to 16 System.out.println("male < 25: " + policy.monthlyPremium()); System.out.println("Expected: 85.5"); //male 25 policy = new Insurance( new Person("Henry", "m", 25)); System.out.println("male 25 to 85: " + policy.monthlyPremium()); System.out.println("Expected: 55.0"); //male 85 policy = new Insurance( new Person("Thong", "m", 85)); System.out.println("male 85: " + policy.monthlyPremium()); System.out.println("Expected: 92.0"); //female 15 policy = new Insurance( new Person("Ashwanee", "f", 15)); System.out.println("underage: " + policy.monthlyPremium()); System.out.println("Expected: -1.0"); //female 16 policy.incrementAge(); System.out.println("female < 25: " + policy.monthlyPremium()); System.out.println("Expected: 79.25");
  • 8. //female 25 policy = new Insurance( new Person("Rebecca", "f", 25)); System.out.println("female 25 to 85: " + policy.monthlyPremium()); System.out.println("Expected: 45.0"); //female 85 policy = new Insurance( new Person("Chen", "f", 85)); System.out.println("female 85: " + policy.monthlyPremium()); System.out.println("Expected: 90.0"); } } -------------------------------------------------------------------------------------------------------------- Sample Output: underage: -1.0 Expected: -1.0 male < 25: 85.5 Expected: 85.5 male 25 to 85: 55.0 Expected: 55.0 male 85: 92.0 Expected: 92.0 underage: -1.0 Expected: -1.0 female < 25: 79.25 Expected: 79.25 female 25 to 85: 45.0 Expected: 45.0 female 85: 90.0 Expected: 90.0