现完成此系统的设计。
public class Test_round {
public static void main(String arg[]){
//1
// Fruit fruit1=new Fruit();
// fruit1.name="苹果";
// fruit1.number=10;
// fruit1.price=20;
// fruit1.text();
//2
// Box boxV=new Box(2,3,4);
// System.out.print(boxV.text());
//3
// Tools tools=new Tools();
// tools.println("women");
// tools.println();
// tools.println(123);
// tools.println(0);
//4
// Temperature temperature=new Temperature(32);
// System.out.print(temperature.text());
//5
// double Htemp=33;
// Temperature temperature=new Temperature(Htemp);
// Tools tools=new Tools();
// tools.println(temperature.text());
//6:Lucy,女,23岁;Jame,男,25岁
// Person man=new Person("Jame",true,25);
// man.walk();man.eat();
// Person woman=new Person("Lucy",false,23);
// woman.walk();woman.eat();
//7.自动继承了父类的属性和方法,所以会先调用父类的构造函数输出
//8.int method()是一个需要返回值的函数 ,而且在父类中已经有一个同名函数了
//void method()是因为在父类中已经有一个一样的函数了
//子类不能重载父类的方法,只能重写或覆盖、子类中父类的同名方法也不可以私有。
//9.调用了父类中的构造函数,可是父类中的是无参数构造函数,这里使用了参数,所以报错,可以将参数删除或者将父类的构造函数中添加上参数
//10
// DBTeacher t = new DBTeacher();//这里创建对象错误,应该为同一个类
// t.sayHi();
// t.giveLesson();
Employee employee =new Employee(001, "emp",0);
employee.monthsal();
employee.text();
Manager manager =new Manager(002, "manager",0);
manager.monthsal();
manager.text();
Director director =new Director(003, "director",0);
director.monthsal();
director.text();
}
}
class Fruit{
String name;
int number;
int price;
public void text()
{
System.out.print(name+":"+number+","+price);
}
}
class Box{
int box1,box2,box3;
public Box(int box1,int box2,int box3){
this.box1=box1;
this.box2=box2;
this.box3=box3;
}
public int text(){
return box1*box2*box3;
}
}
class Tools{
public void println()
{
System.out.print('\n'); // 换行
}
public void println(String info){
System.out.print(info);
}
public void println(double info){
System.out.print(info);
}
public void println(Boolean info){
System.out.print(info);
}
}
class Temperature{
double Stemp;
public Temperature(double Stemp)
{
this.Stemp=Stemp;
}
public double text(){
return (Stemp-32)*5/9;
}
}
class Person{
String name;
boolean gender;
int age;
public Person(String name,boolean gender,int age){
this.name=name;
this.gender=gender;
this.age=age;
}
public void walk(){
System.out.print(name+"在行走");
}
public void eat(){
System.out.print(name+"在吃东西");
}
}
/*
3)设计一个Tools类提供重载方法println()和println(String info),让其接收不同的数据并能打印字符串,数字,布尔值和换行打印。
*/
class Teacher {
public void giveLesson() {
System.out.println("知识点讲解");
System.out.println("总结提问");
}
}
class DBTeacher extends Teacher {
public void giveLesson() {
System.out.println("启动 SqlServer");
super.giveLesson();
}
public void sayHi() {
System.out.println("Hi");
}
} /*
11).在员工管理系统中,有普通员工,经理,董事三种角色,公司所有的员工都有员工Id,员工名字,员工基本薪水(2000),请假天数;
现初步定Employee类为父类,Manager子类、Director(董事)子类,它们的区别
是计算工资方式不一样。
具体工资计算办法:
A、工资扣除部分:如果请假小于5天,基本工资发75%,大于5天,基本工资发50% ;
B、经理的工资=基本工资+住房补贴(基本工资的0.2)+交通补贴(基本工资的0.5)+医疗补贴(500) ;
C、董事的工资=基本工资+住房补贴(基本工资的0.08)+交通补贴(基本工资的0.3)+医疗补贴(2000)+娱乐补贴(3000) ;
现完成此系统的设计。*/
class Employee{
int id;
String name;
double sal=2000;
int relaxday;
public Employee(int id,String name,int relaxday){
this.id=id;
this.name=name;
this.relaxday=relaxday;
}
public void monthsal(){
if (1<=relaxday&&relaxday<=5) {
sal=sal*0.75;
}
else if(relaxday>5)
sal=sal*0.5;}
public void text(){
System.out.print("id:"+id+","+"名字:"+name+","+"工资:"+sal+","+"请假天数:"+relaxday+","+'\n');
}
}
//B、经理的工资=基本工资+住房补贴(基本工资的0.2)+交通补贴(基本工资的0.5)+医疗补贴(500) ;
class Manager extends Employee{
public Manager(int id, String name, int relaxday) {
super(id, name, relaxday);
// TODO Auto-generated constructor stub
}
public void monthsal()
{
if (1<=relaxday&&relaxday<=5) {
sal=sal*0.75;
}
else if(relaxday>5) sal=sal*0.5;
sal=sal+sal*0.2+sal*0.5+500;
}
}
//C、董事的工资=基本工资+住房补贴(基本工资的0.08)+交通补贴(基本工资的0.3)+医疗补贴(2000)+娱乐补贴(3000) ;
class Director extends Employee{
public Director(int id, String name,int relaxday) {
super(id, name, relaxday);
// TODO Auto-generated constructor stub
}
public void monthsal()
{
if (1<=relaxday&&relaxday<=5) {
sal=sal*0.75;
}
else if(relaxday>5)
sal=sal*0.5;
sal=sal+sal*0.08+sal*0.3+5000;
}
}