Java programming assignment: A student is a person, and so is an employee. Creat
ID: 667356 • Letter: J
Question
Java programming assignment:
A student is a person, and so is an employee. Create a class Person that has the data attributes common to both students and employees (names, social security number, age, gender, address, and telephone number) and appropriate method definitions. A student has a grade-point average (GPA), major, and year of graduation. An employee has a department, job title, and year of hire. In addition, there are hourly employees (hourly rate, hours worked, and union dues) and salaried employees (annual salary). Define a class hierarcy and write an application class that you can use to first store the data for an array of people and then display that information in a meaninful way.
The task asks you to write an application class for storing the data (array of people) and displaying that info. Write a test program that uses all those features and, additionally, allows for entering additional data by the user. You can either:
a. follow the textbook’s requirements for an application class, and then have a testprogram to invoke it and, additionally, provide a data entry facility OR
b. add data entry functionality to the application class mentioned in your textbook.
After you create a class Person, write a test program demonstrating how it is used. Upon launching, the program should store a few records of different kind and then allow for entering additional data by the user.
Explanation / Answer
import java.util.*;
import java.io.*;
class person{
String name;
String soc_num;
int age;
String gender;
String address;
String tel_num;
public person(String n,String s,int a,String g,String add,String tel){
name = n;
soc_num = s;
age = a;
gender = g;
address = add;
tel_num = tel;
}
void set_name(String n){
name = n;
}
String get_name(){
return name;
}
void set_soc_num(String s){
soc_num = s;
}
String set_soc_num(){
return soc_num;
}
void set_age(int a){
age = a;
}
int get_age(){
return age;
}
void set_gender(String g){
gender = g;
}
String get_gender(){
return gender;
}
void set_Address(String a){
address = a;
}
String get_address(){
return address;
}
void set_tel(String t){
tel_num = t;
}
String get_tel(){
return tel_num;
}
}
class student extends person{
// Grade pointer
double cgpa;
// Major
String major;
// Year of graduation
int year;
public student(String n,String s,int a,String g,String add,String tel,double cg,String maj,int yr){
super(n,s,a,g,add,tel);
cgpa = cg;
major = maj;
year = yr;
}
}
class employee extends person{
String department;
String job_title;
int year_hire;
public employee(String n,String s,int a,String g,String add,String tel,String dep,String title,int yr){
super(n,s,a,g,add,tel);
department = dep;
job_title = title;
year_hire = yr;
}
}
/* Name of the class has to be "Main" only if the class is public. */
class Ideone{
public static void main (String[] args) throws java.lang.Exception{
person[] p = new person[2];
p[0] = new student("A","12",12,"Male","CICR SIRSA INDIA","9782",6.3,"Computer Science",2012);
p[1] = new employee("A","12",12,"Male","CICR SIRSA INDIA","9782","HealthCare","Scientist",1982);
}
}
Check http://ideone.com/j5DA3O for output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.