package top.qaqaq.java.P267;
/*
定义一个ManKind类,包括
成员变量int sex和int salary;
方法void manOrWoman():根据sex的值显示“man”(sex==1)或者“woman”(sex==0);
方法void employeed():根据salary的值显示“no job”(salary==0)或者“ job”(salary!=0)。
*
*
*/
public class ManKind {
private int sex;// 性别
private int salary;// 薪资
public ManKind() {
}
public ManKind(int sex, int salary) {
this.sex = sex;
this.salary = salary;
}
public void manOrWoman() {
if (sex == 1) {
System.out.println("man");
} else if (sex == 0) {
System.out.println("woman");
}
}
public void employeed() {
// if(salary == 0) {
// System.out.println("no job");
// }else {
// System.out.println("job");
// }
// 或
String jobInfo = (salary == 0) ? "no job" : "job";
System.out.println(jobInfo);
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
}
package top.qaqaq.java.P267;
/*
定义类Kids继承ManKind,并包括
成员变量int yearsOld;
方法printAge()打印yearsOld的值。
*
*
*/
public class Kids extends ManKind {
private int yearsOld;
public Kids() {
}
public Kids(int yearsOld) {
this.yearsOld = yearsOld;
}
public void printAge() {
System.out.println("I am " + yearsOld + " years old.");
}
public int getYearsOld() {
return yearsOld;
}
public void setYearsOld(int yearsOld) {
this.yearsOld = yearsOld;
}
}
package top.qaqaq.java.P267;
/*
* 定义类KidsTest,在类的main方法中实例化Kids的对象someKid,用该对象访问其父类的成员变量及方法。
*
*
*/
public class KidsTest {
public static void main(String[] args) {
Kids someKid = new Kids(12);
someKid.printAge();
someKid.setSalary(0);
someKid.setSex(1);
someKid.employeed();
someKid.manOrWoman();
}
}
package top.qaqaq.java.P267;
public class Person {
String name;
char sex;
int age;
public Person() {
}
public Person(String name,char sex,int age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public String toString() {
return name + sex + age;
}
}
package top.qaqaq.java.P267;
public class Student extends Person {
long number;
int math;
int english;
int computer;
public Student() {
}
public Student(String n, char s, int a, long k, int m, int e, int c) {
this.name = n;
this.sex = s;
this.age = a;
this.number = k;
this.math = m;
this.english = e;
this.computer = c;
}
public double aver() {
return math + english + computer;
}
public int max() {
int max1 = (math > english)? math : english;
int max2 = (max1 > computer)? max1 : computer;
return max2;
}
public int min() {
int min1 = (math < english)? math : english;
int min2 = (min1 < computer)? min1 : computer;
return min2;
}
public String toString() {
return name +sex + age + number + math + english + computer;
}
}