Java编程题目,菜鸟求答案!高分在线等!!!好的追加高分!!!

编程题目:定义类Person及其子类Student、Employee,每个类定义下列成员变量。Person:姓名,年龄,家庭住址。Student:学号,年级。Employ... 编程题目:

定义类Person及其子类Student、Employee,每个类定义下列成员变量。
Person:姓名,年龄,家庭住址。
Student:学号,年级。
Employee:工资,受聘日期,定义MyDate表示受聘日期,成员变量包括年,月,日。

每个类定义构造方法初始化所有变量,覆盖toString()方法输出所有成员变量值。创建每个类的对象,并调用toString()方法。

PS,所编程序最好放着一个Java文件中。
展开
 我来答
flyingFish211
2011-11-28 · TA获得超过2.1万个赞
知道大有可为答主
回答量:1.5万
采纳率:50%
帮助的人:1.1亿
展开全部
//File name: Test.java

public class Test {

public static void main(String[] args) {

MyDate date = new MyDate(2011, 11, 28);
System.out.println("Date is: " + date.toString());

Person person = new Person("Zhang San", 22, "hangzhou");
System.out.println("Person detail:" + person.toString());

Student student = new Student("Zhang San", 22, "Hangzhou", 1234, 3);
System.out.println("Student details: " + student.toString());

Employee employee = new Employee("Teacher Zhang", 35, "Suzhou", 20000, date);
System.out.println("Employee information: " + employee.toString());
}

}

class Person{
protected String name;
protected int age;
protected String address;

public Person(String name, int age, String address){
this.name = name;
this.age = age;
this.address = address;
}

public String toString(){
return name + ": " + name + ", age: " + age + ", address: " + address;
}

}

class Student extends Person{
private int stuNumber;
private int grade;

public Student(String name, int age, String address, int stuNumber, int grade) {
super(name, age, address);
this.stuNumber = stuNumber;
this.grade = grade;
}

public String toString(){
return super.toString() + ", stuNumber: " + stuNumber + ", grade: " + grade;
}

}

class Employee extends Person{
private double salary;
private MyDate dateHired;

public Employee(String name, int age, String address, double salary, MyDate date) {
super(name, age, address);
this.salary = salary;
this.dateHired = date;
}

public String toString(){
return super.toString() + ", salary: " + salary + ", date Hired: " + dateHired.toString();
}
}

class MyDate{
private int year;
private int month;
private int date;

public MyDate(int year, int month, int date){
this.year = year;
this.month = month;
this.date = date;
}

public String toString(){
return year + "/" + month + "/" + date;
}
}
才闻楣08j
2011-11-28 · 超过14用户采纳过TA的回答
知道答主
回答量:31
采纳率:0%
帮助的人:31.7万
展开全部
文件名Person.java
public class Person {

private String name ;
private int age ;
private String address;

public Person()
{

}
public Person(String name,int age,String address)
{
this.name=name;
this.age=age;
this.address=address;
}
@Override
public String toString() {
return "Person [address=" + address + ", age=" + age + ", name=" + name
+ "]";
}
}

class Student extends Person{

private String Snumber ;
private String Sgrade;

public Student(){
}
public Student(String name,int age,String address,String number ,String grade){
super(name, age, address);
this.Snumber=number;
this.Sgrade=grade;
}
@Override
public String toString() {
return "Student [Sgrade=" + Sgrade + ", Snumber=" + Snumber
+ ", toString()=" + super.toString() + ", getClass()="
+ getClass() + ", hashCode()=" + hashCode() + "]";
}
}

class Mydate{
private String year;
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
private String month;
private String day;
}

class Employee extends Person{

private String salary;
private Mydate eDate ;
public Employee(){

}
public Employee(String name,int age,String address,String salary, Mydate eDate) {
super(name, age, address);
this.salary = salary;
this.eDate = eDate;
}

@Override
public String toString() {
return "Employee [eDate=" + eDate + ", salary=" + salary
+ ", toString()=" + super.toString() + ", getClass()="
+ getClass() + ", hashCode()=" + hashCode() + "]";
}
}

class test{
public static void main(String args[]){

//测试自己在这里写
Mydate md =new Mydate(); //这是Employee的其它的依照自己写吧,我就不写了!!!
md.setYear("2011");
md.setMonth("11");
md.setDay("28");
Employee ep=new Employee("张三",23,"重庆","5000",md);
ep.toString();

}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式