用java设计一个程序
发布网友
发布时间:2022-05-15 18:22
我来回答
共4个回答
热心网友
时间:2024-02-26 07:44
Employee类:
public class Employee {
private String name;
private String num;
private String telphone;
public Employee(String name,String num,String telphone){
this.name=name;
this.num=num;
this.telphone=telphone;
}
protected void show(){
System.out.println("姓名:"+name);
System.out.println("工号:"+num);
System.out.println("电话号码:"+telphone);
}
}
Faculty类:
public class Faculty extends Employee{
private String office;
private double wage;
private int year;
public Faculty(String name,String num,String telphone,String office,double wage,int year){
super( name,num,telphone);
this.office=office;
this.wage=wage;
this.year=year;
}
protected void show(){
super.show();
System.out.println("办公室:"+office);
System.out.println("工资:"+wage);
System.out.println("年限:"+year);
}
}
主类:
public class App {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Faculty fa=new Faculty("时空","2015","110","广州",10000,10);
fa.show();
}
}
运行结果:
姓名:时空
工号:2015
电话号码:110
办公室:广州
工资:10000.0
年限:10
希望能帮到你
热心网友
时间:2024-02-26 07:44
package com.test;
public class Employee {
// 姓名
String name;
// 工号
String num;
// 电话号码
String telphone;
public void init(String name, String num, String telphone) {
this.name = name;
this.num = num;
this.telphone = telphone;
}
public void show() {
System.out.println("姓名:" + name);
System.out.println("工号:" + num);
System.out.println("电话号码:" + telphone);
}
}
package com.test;
public class Faculty extends Employee {
Faculty(String name, String num, String telphone) {
super.init(name, num, telphone);
}
String office;
double wage;
int year;
public void init(String office, double wage, int year) {
this.office = office;
this.wage = wage;
this.year = year;
}
public void show() {
super.show();
System.out.println("办公室:" + office);
System.out.println("工资:" + wage);
System.out.println("受雇年限:" + year);
}
}
package com.test;
public class FacultyTest {
public static void main(String[] args) {
Faculty faculty = new Faculty("张三", "001", "13888888888");
faculty.init("701", 2044, 3);
faculty.show();
}
}
热心网友
时间:2024-02-26 07:45
//Employee
public class Employee {
private String name;
private String num;
private String telphone;
public Employee(String name, String num, String telphone) {
this.name = name;
this.num = num;
this.telphone = telphone;
}
public void show()
{
System.out.println("姓名: "+name+" 工号: "+num+" 电话: "+telphone);
}
}
//Faculty
public class Faculty extends Employee {
private String office;
private double wage;
private int year;
public Faculty(String name, String num, String telphone, String office,
double wage, int year) {
super(name, num, telphone);
this.office = office;
this.wage = wage;
this.year = year;
}
@Override
public void show() {
// TODO Auto-generated method stub
super.show();
System.out.println("办公室: "+office+" 工资: "+wage+" 受雇年限: "+year);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Faculty f=new Faculty("小风","001","12345678","建筑部",2000.00,2);
f.show();
}
}
热心网友
时间:2024-02-26 07:46
我只对个人发送。