Assignment 10 Workshop Type solution and submit as an attachment. All member are
ID: 3780389 • Letter: A
Question
Assignment 10 Workshop Type solution and submit as an attachment. All member are responsible all the quntiorun. Type 1. Create the clus Name that has the following propertie: private string field naared frutName. private string field maaaed public defaul coustructor that auaigur the empty striag to all the fields. publie overloaded coustrueto that takes two (2) striug paaameters fe fredNe ome aad lastNawe Public overloaded a operator. public set acceseor methods for all fields. public get aneemson amethods for all fields, public string method named foString that takes Do pararletenk retums the firstName followed by lautNewat separated by a space. 2. Create the class Person that has the following properties: private Name field naawed name. Private integr fild named D public default constaator that aasigas the default Name object to name and I to publie ewerloaded couatructor that takos a Name parameter and isteget parameter. he parameters to their appropiate fields. public set and get aceeaor talethods for all Belk. It returau the Nanae followed age separated by Create the claus Student that has the following properties: publicly inherits Person. private tring field naaed Neajor. public default coustractor that calls the defaut coustructor of Person assigas Liberal Arts" public overloaded constractor that takom a Name, integer aad string paraameters. assigns the to their appropiate fields. art and get accow-or aethods for all Soldx. publi string method sauned restring that takes no parameters. returns the Ranae followed by age separated counma and ou the next line major.Explanation / Answer
1.
public class Name
{
private String firstName;
private String lastName;
public Name() //default constructor
{
firstName="";
lastName="";
}
public Name(String first, String last) //overloaded constructor
{
first=firstName;
last=lastName;
}
String concat = firstName + lastName; //overloaded assingment operator
//Mutator for firstname
public void setfirstName(String f)
{
this.firstName= f;
}
//Mutator for lastname
public void setlastName(String l)
{
this.lastName= l;
}
public String getfirstName() //Accessor for firstName
{
return this.firstName;
}
public String getlastName() //Accessor for lastName
{
return this.lastName;
}
public String toString()
{
return firstName + " " + lastName;
}
}
2. class Person
{
private String name;
private int age;
public Person() //default constructor
{
name="JAVA";
age=1;
}
public Person(String n, int a) //overloaded constructor
{
n=name;
a=age;
}
//Mutator for name
public void setName(String na)
{
this.name= na;
}
//Mutator for age
public void setage(int ag)
{
this.age=ag;
}
public String getName() //Accessor for Name
{
return this.name;
}
public int getage() //Accessor for age
{
return this.age;
}
public String toString()
{
return "name: "+name+ ", " + "age: " + age;
}
}