JAVA PROGRAM.. In this assignment you are asked to write a JAVA program and comp
ID: 3755229 • Letter: J
Question
JAVA PROGRAM..
In this assignment you are asked to write a JAVA program and complete the following tasks: Create a class called Person that has two instance variables (attributes), one for the person's name and the other for the person's age. (1pt) Include accessor methods and mutator (getters and setters) methods for each instance variable. (1pt) Include a method that sets both the name and the age of a person. (2pts) Write a Driver class (with a main) to instantiate two objects from the class Person. Initialize the objects using the method in item 3. You may choose any name and age (2pts) Within the driver class create a method, older, that will determine which one of your two persons are older. This method should appropriately print the name of that person. (3pts) Ensure that you have written the Javadoc comments for all methods.(1pt) 1. 2. 3. 4. 5. 6. 7. Submit the following: a) The Person Class file. b) The Driver Class file. c) Ascreenshot of eclipse showing the output.Explanation / Answer
import java.util.*;
class Person
{
private String name;
private int age;
Person(String _name,int _age) {
name=_name;
age=_age;
}
public void setName(String _name)
{
name=_name;
}
public void setAge(int _age)
{
age=_age;
}
public String getname()
{
return name;
}
public int getAge()
{
return age;
}
}
class Derive
{
Person a=new Person("Prashant",24);
Person b=new Person("Chegg",100000);
public void older()
{
if(a.getAge()>b.getAge())
{
System.out.println(a.getname()+" is Older then "+b.getname());
}
else
{
System.out.println(b.getname()+" is Older then "+a.getname());
}
}
}
public class Main
{
public static void main(String[] args)
{
Derive d=new Derive();
d.older();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.