java-day10

第十天:

 

高内聚   低耦合

继承 >  关联 >  依赖

Test1

父类:TuXing

package test1;

 

public abstract class TuXing {

    private String point;

    public TuXing(String point){

        this.point = point;

    }

    public abstract void draw();

}

 

 

1.SanJiaoXing

package test1;

 

public class SanJiaoXing extends TuXing {

 

    public SanJiaoXing(String point) {

        super(point);

    }

 

    public void draw() {

 

    }

}

 

 

.2.JuXing

package test1;

 

public class JuXing extends TuXing {

 

    public JuXing(String point){

        super(point);

    }

    public void draw() {

        System.out.println("ju xing");

    }

}

 

 

 

Test2

父类:Vehicle

package test2;

 

public abstract class Vehicle {

    public abstract String NoOfWheels();

}

 

1.Car

package test2;

 

public class Car extends Vehicle {

 

    public String NoOfWheels() {

        return "silunche";

    }

}

 

2.Motorbike

package test2;

 

public class Motorbike extends Vehicle {

 

    public String NoOfWheels() {

        return "shuanglunche";

    }

}

 

 

3.Test

package test2;

 

public class Test {

    public static void main(String[] args){

        Vehicle v1 = new Car();

        Vehicle v2 = new Motorbike();

        String s1 = v1.NoOfWheels();

        String s2 = v2.NoOfWheels();

        System.out.println(s1);

        System.out.println(s2);

    }

}

 

 

test3

1.interfaceDemo

package test3;

 

public class interfaceDemo {

    public static void main(String[] args){

       Vehicle v1 = new Bike();

       Vehicle v2 = new Bus();

       v1.start();

       v1.stop();

       v2.start();

       v2.stop();

    }

}

 

 

interface Vehicle

package test3;

 

public interface Vehicle {

    public void start();

    public void stop();

}

 

 

Bus

package test3;

 

public class Bus implements Vehicle {

    @Override

    public void start() {

        System.out.println("bus start");

    }

 

    @Override

    public void stop() {

        System.out.println("bus stop");

    }

}

 

 

Bike

package test3;

 

public class Bike implements Vehicle {

    @Override

    public void start() {

        System.out.println("bike start");

    }

 

    @Override

    public void stop() {

        System.out.println("bike stop");

    }

}

 

 

Test5

1.DoorInterface

package test5;

 

public interface DoorInterface {

    public void theftproof();

    public void waterproof();

    public void bulletproof();

}

 

 

Door

package test5;

 

public abstract class Door implements DoorInterface{

    public void openDoor(){

 

    }

    public void closeDoor(){

 

    }

}

 

 

 

test7

MyDate

package test7;

 

public class MyDate {

    private String month;

    private String day;

    private String year;

 

    public MyDate(String month, String day, String year) {

        this.month = month;

        this.day = day;

        this.year = year;

    }

 

    public String toDateString(){

        return year+"年"+month+"月"+day+"日";

    }

}

 

 

SalariedEmployee

package test7;

 

public class SalariedEmployee extends Employee {

    private int monthlySalary;

 

    @Override

    public int earnings() {

        return monthlySalary;

    }

 

    @Override

    public String toString() {

        return "SalariedEmployee{" +

                "monthlySalary=" + monthlySalary +

                '}'+super.toString();

    }

}

 

 

HourlyEmployee

package test7;

 

public class HourlyEmployee extends Employee{

    private int wage;

    private int hour;

 

    @Override

    public int earnings() {

        return wage*hour;

    }

 

    @Override

    public String toString() {

        return "HourlyEmployee{" +

                "wage=" + wage +

                ", hour=" + hour +

                '}'+super.toString();

    }

}

 

 

package test7;

 

public abstract class Employee {

    private String name;

    private String number;

    private MyDate birthday;

 

    public abstract int earnings();

 

 

    public String toString() {

        return "Employee{" +

                "name='" + name + '\'' +

                ", number='" + number + '\'' +

                ", birthday=" + birthday +

                '}';

    }

}

 

 

 

 

test91

 Person

package test91;

//jicheng   guanlian   yilai

public class Person {

 

    private String name;

    private int age;

    private String sex;

 

    public String getName() {

        return name;

    }

 

    public void setName(String name) {

        this.name = name;

    }

 

    public int getAge() {

        return age;

    }

 

    public void setAge(int age) {

        this.age = age;

    }

 

    public String getSex() {

        return sex;

    }

 

    public void setSex(String sex) {

        this.sex = sex;

    }

}

 

 

Student

package test91;

 

public class Student extends Person {

    private int a1;

    private int a2;

    private int a3;

    private int a4;

    private int a5;

 

    public int getA1() {

        return a1;

    }

 

    public void setA1(int a1) {

        this.a1 = a1;

    }

 

    public int getA2() {

        return a2;

    }

 

    public void setA2(int a2) {

        this.a2 = a2;

    }

 

    public int getA3() {

        return a3;

    }

 

    public void setA3(int a3) {

        this.a3 = a3;

    }

 

    public int getA4() {

        return a4;

    }

 

    public void setA4(int a4) {

        this.a4 = a4;

    }

 

    public int getA5() {

        return a5;

    }

 

    public void setA5(int a5) {

        this.a5 = a5;

    }

 

    public int avg(){

        return (a1+a2+a3+a4+a5)/5;

    }

}

 

 

 

 

 

test92

ShaiZi

package test92;

 

public class ShaiZi {

    private int mian;

    private int dian;

    public static int random;

 

    public void roll(){

        random = (int)(Math.random()*6+1);

    }

}

 

 

 

test93

Hero

package test93;

 

public class Hero {

    private String name;

    private int power;

    private int level;

 

    public Hero(int power, int level) {

        this.power = power;

        this.level = level;

    }

    public Hero(int type){

        if(type==1){

            this.power = 100;

            this.level = 1;

        }else if(type==2){

            this.power = 200;

            this.level = 2;

        }else {

            System.out.println("");

        }

    }

 

    public String getName() {

        return name;

    }

 

    public void setName(String name) {

        this.name = name;

    }

 

    public void zhanDou(Hero h){

        h.power -= 10;

    }

    public void jueZhao(JueZhao j,Hero h){

 

    }

 

}

 

 

JueZhao

package test93;

 

public interface JueZhao {

}

 

 

JYZJ

package test93;

 

public class JYZJ implements JueZhao {

}

 

 

QKDNY

package test93;

 

public class QKDNY implements JueZhao {

}

 

 

 

test98

student

package test98;

 

 

 

public class student{

 

    private String name;

    private int score;

 

    public student(String name, int score) {

        this.name = name;

        this.score = score;

    }

 

    public String getName() {

        return name;

    }

 

    public void setName(String name) {

        this.name = name;

    }

 

    public int getScore() {

        return score;

    }

 

    public void setScore(int score) {

        this.score = score;

    }

 

    @Override

    public String toString() {

        return "student{" +

                "name='" + name + '\'' +

                ", score=" + score +

                '}';

    }

}

 

 

 MyCom

package test98;

 

import java.util.Comparator;

 

public class MyCom implements Comparator {

    public int compare(Object o1, Object o2) {

        student s1 = (student)o1;

        student s2 = (student)o2;

        if(s1.getScore()>s2.getScore()){

            return -1;

        }else if(s1.getScore()<s2.getScore()){

            return 1;

        }

        return 0;

    }

}

 

 

Test

package test98;

 

import java.util.Arrays;

 

public class Test {

    public static void main(String[] args){

        student[] students = new student[10];

        for (int i=0;i<10;i++){

            student s = new student(String.valueOf(i),(int)(Math.random()*101));

            students[i] = s;

        }

        Arrays.sort(students,new MyCom());

        for (int i=0;i<10;i++){

            System.out.println(students[i]);

        }

    }

}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值