码迷,mamicode.com
首页 > 其他好文 > 详细

东软实训作业

时间:2015-07-14 22:06:53      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

//作业1

/**
 * Created by doggy on 15-7-14.
 */
public class Music {
    public static void main(String[] main){
        Instrument i1 = new Wind();
        Instrument i2 = new Brass();
        tune(i1);
        tune(i2);
    }
    public static void tune(Instrument i){
        i.play();
    }
}
abstract class Instrument{
    public abstract void play();
}
class Wind extends Instrument{
    @Override
    public void play() {
        play1();
        System.out.println("弹奏Wind");
    }
    public void play1(){
        System.out.println("调用Wind.play1()");
    }
}
class Brass extends Instrument{
    public void play() {
        play2();
        System.out.println("弹奏Brass");
    }
    public void play2(){
        System.out.println("调用Brass.play2()");
    }
}

//作业2

//作业3

/**
 * Created by doggy on 15-7-14.
 */
public class A {
    public static void main(String[] args){
        Lader l = new Lader(1,2,3);
        System.out.println(l.getArea());
        Circle c = new Circle(3);
        System.out.println(c.getArea());
        System.out.println(c.getLength());
    }
}

class Lader{
    private double ul;
    private double dl;
    private double height;
    private double area;

    Lader(double ul,double dl,double height){
        this.ul = ul;
        this.dl = dl;
        this.height = height;
    }

    double getArea(){
        area = (ul+dl)*height/2;
        return area;
    }
}
class Circle{
    private double r;
    private double area;
    private double length;

    Circle(double r){
        this.r = r;
    }

    double getArea(){
        area =  Math.PI*r*r;
        return area;
    }
    double getLength(){
        length = Math.PI * 2 * r;
        return length;
    }
}

//作业4

/**
 * Created by doggy on 15-7-14.
 */
public class E {
    public static void main(String[] args){
        Interface1 i1 = new Print();
        Interface2 i2 = new Print();
        i1.printCapitalLetter();
        i2.printLowercaseLetter();
    }
}

interface Interface1{
    void printCapitalLetter();
}
interface Interface2{
    void printLowercaseLetter();
}
class Print implements Interface1,Interface2{
    @Override
    public void printCapitalLetter() {
        System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }

    @Override
    public void printLowercaseLetter() {
        System.out.println("abcdefghijklmnopqrstuvwxyz");
    }
}

//作业5

/**
 * Created by doggy on 15-7-14.
 */
public class XiYouJiRenWu {
    private float height;
    private String name;
    private String weapon;

    void printName(){
        System.out.println(name);
    }
    void printWeapon(){
        System.out.println(weapon);
    }
    XiYouJiRenWu(String name,String weapon){
        this.name = name;
        this.weapon = weapon;
    }
    public static void main(String[] args){
        XiYouJiRenWu x1 = new XiYouJiRenWu("zhuBaJie","钉耙");
        XiYouJiRenWu x2 = new XiYouJiRenWu("xunWuKon","棒子");
        x1.printName();
        x1.printWeapon();
        x2.printName();
        x2.printWeapon();
    }
}

//作业6

package w6;

/**
 * Created by doggy on 15-7-14.
 */
public class E {
    public static void main(String[] args){
        InterfaceA a = new ClassA();
        System.out.println(a.method(10));
        a = new ClassB();
        System.out.println(a.method(10));
    }
}
interface InterfaceA{
    int method(int i);
}
class ClassA implements InterfaceA{
    @Override
    public int method(int i) {
        int count = 0;
        for(int j = 1;j <= i;++j){
            count += j;
        }
        return count;
    }
}
class  ClassB implements  InterfaceA{
    @Override
    public int method(int i) {
        int count = 1;
        for(int j = 1;j <= i;++j){
            count *= j;
        }
        return count;
    }
}

//作业7

/**
 * Created by doggy on 15-7-14.
 */
public class W7_E {
    public static void main(String[] args){
        Province p = new Province();
        p.partyLeader();
        p.safetyInProduction();
    }

}
interface CentralPartyCommitte{
    void partyLeader();
}
abstract class StateCouncil {
    abstract void safetyInProduction();
}

class Province extends StateCouncil implements CentralPartyCommitte {
    @Override
    public void partyLeader() {
        System.out.println("坚持党的领导");
    }

    @Override
    void safetyInProduction() {
        System.out.println("进行安全生产");
    }
}

//作业8

/**
 * Created by doggy on 15-7-14.
 */
public class W8_People {
    protected double height;
    protected double weight;
    public void speakHello(){}
    public void averageHeight(){}
    public void averageWeight(){}
}
class ChinaPeople extends W8_People{
    @Override
    public void speakHello(){
        System.out.println("你好");
    }
    public void chinaGongFu(){
        System.out.println("坐如钟");
    }
}
class AmericanPeople extends W8_People{
    @Override
    public void speakHello(){
        System.out.println("hello");
    }
    public void americanBoxing(){
        System.out.println("勾拳");
    }
}

//作业9

/**
 * Created by doggy on 15-7-14.
 */
public class W9_E {
    public static void main(String[] args){
        Account a = new Account(123);
        System.out.println(a.left());
        a.save(1);
        System.out.println(a.left());
        a.get(100);
        System.out.println(a.left());
    }
}
class Account{
    private int money;
    private long id;
    Account(int money){this.money = money;}
    public void save(int x){
        money += x;
    }
    public  void get(int x){
        money -= x;
    }
    public int left(){
        return money;
    }
}

//作业10

/**
 * Created by doggy on 15-7-14.
 */
public class W10_Test {
    public static void main(String[] args){
        Clock c1 = new Clock(1,2,3);
        Clock c2 = new Clock(9,22,3);
        c1.show();
        c2.show();
    }
}
class Clock{
    private int hour;
    private int minute;
    private int second;
    Clock(int hour,int minute,int second){
        this.hour = hour;
        this.minute = minute;
        this.second = second;
    }
    void show(){
        System.out.printf("%d:%d:%d\n", hour, minute, second);
    }
}

 

东软实训作业

标签:

原文地址:http://www.cnblogs.com/fcat/p/4646519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!