【安博培训笔记】Java1 Java面向对象_PPT练习20130920

package com.ambow.java20130917;

public class Student {
	private String name;
	private int age;
	private int banji;
	private String love;
	
	
	public Student(String name) {
		super();
		this.name = name;
	}




	public Student(String name, int age, int banji) {
		super();
		this.name = name;
		this.age = age;
		this.banji = banji;
	}




	public Student(String name, int age, int banji, String love) {
		super();
		this.name = name;
		this.age = age;
		this.banji = banji;
		this.love = love;
	}



	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}


	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}


	/**
	 * @return the age
	 */
	public int getAge() {
		return age;
	}


	/**
	 * @param age the age to set
	 */
	public void setAge(int age) {
		this.age = age;
	}


	/**
	 * @return the banji
	 */
	public int getBanji() {
		return banji;
	}


	/**
	 * @param banji the banji to set
	 */
	public void setBanji(int banji) {
		this.banji = banji;
	}


	/**
	 * @return the love
	 */
	public String getLove() {
		return love;
	}


	/**
	 * @param love the love to set
	 */
	public void setLove(String love) {
		this.love = love;
	}

	
	public void display() {
		System.out.println(name+" "+this.age+" "+banji+" "+this.love);
	}
}

package com.ambow.java20130917;public class Sample {public static void main(String[ ] args) { Child c = new Child(); c.method(); }}

package com.ambow.java20130917;

public class TeacherTest {
	public static void main(String[] args){

        JavaTeacher jt=new JavaTeacher("李飞","计算机系");
        jt.introduction();
        jt.giveLesson();

        NetTeacher nt=new NetTeacher("王刚","计算机系");
        nt.introduction();
        nt.giveLesson();
 }
}

package com.ambow.java20130917;

public class Child extends Base {
	public Child(){
		super("Child1");
		name="Child2";
		}
}

package com.ambow.java20130917;

public class Animal {
	public void eat() {
		System.out.println("eat");
	}
	public void sleep() {
		System.out.println("sleep");
	}

}

package com.ambow.java20130917;

public class StudentTest {
	public static void main(String[] args) {
		Student student = new Student("付仕华", 22, 02, "睡觉");
		student.display();
		Student student2 = new Student("付仕华");
		student2.display();
	}
}

package com.ambow.java20130917;

public class Teacher {
	private String name;   // 教师姓名
	private String dept; // 所在系部
	public Teacher(String myName,
	                                String myDept) {
	name = myName;
	dept = myDept;
	}
	public void giveLesson(){
	System.out.println("知识点讲解");
	System.out.println("课堂总结");
	}
	       public void introduction() {
		System.out.println("大家好!我是"+ dept + "的" + name + "。");
	}
}

package com.ambow.java20130917;

public class AnimalTiger extends Animal{
	public void eat() {
		System.out.println("老虎吃肉");
	}
}

package com.ambow.java20130917;

public class Base {
	public String name;
	public Base(){
	name = "Base";
	}
	public Base(String pName){
	name = pName;
	}
	public void method(){
	System.out.println(name);
	}
}

package com.ambow.java20130917;

public class Book {
	private String title;
	private int pageNum;
	
	public Book(String a,int b){
		setTitle(a);
		if(b<=100)
			setPageNum(100);
		else
			setPageNum(b);
	}


	public int getPageNum() {
		return pageNum;
	}



	public void setPageNum(int pageNum) {
		if (pageNum <=100)
			this.pageNum = 100;
		else
			this.pageNum = pageNum;
	}



	public String getTitle() {
		return title;
	}



	public void setTitle(String title) {
		this.title = title;
	}
	
	public void display() {
		System.out.println(this.title+" "+this.pageNum);
		
	}
	
	public static void main(String[] args) {
		Book b = new Book("红豆",50);
		b.setPageNum(1000);
		b.display();
	}
}

package com.ambow.java20130917;

public class Book1 {
	private String title;
	private int pageNum;
	private String type;
	public Book1(String title, int pageNum) {
		super();
		this.title = title;
		this.pageNum = pageNum;
		this.type = "计算机";
	}
	public Book1(String title, int pageNum, String type) {
		super();
		this.title = title;
		this.pageNum = pageNum;
		this.type = type;
	}
	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}
	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	/**
	 * @return the pageNum
	 */
	public int getPageNum() {
		return pageNum;
	}
	/**
	 * @param pageNum the pageNum to set
	 */
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}
	
	public void display() {
		System.out.println("title="+getTitle()+" pageNum="+getPageNum()
			+" type="+getType());
	}

}

package com.ambow.java20130917;

public class BookTest {
	public static void main(String[] args) {
		Book book = new Book("红豆", 50);
		book.display();
		
	}

}

package com.ambow.java20130917;

public class Book1Test {
	public static void main(String[] args) {
		Book1 book1 = new Book1("浪潮之巅", 100);
		book1.display();
		Book1 book12 = new Book1("红豆", 10, "心灵驿站");
		book12.display();
	}

}

package com.ambow.java20130917;

public class table {
	private String color;
	private double length;
	private double width;
	private double height;
	public table(String color, double length, double width, double height) {
		super();
		this.color = color;
		this.length = length;
		this.width = width;
		this.height = height;
	}
	/**
	 * @return the color
	 */
	public String getColor() {
		return color;
	}
	/**
	 * @param color the color to set
	 */
	public void setColor(String color) {
		this.color = color;
	}
	/**
	 * @return the length
	 */
	public double getLength() {
		return length;
	}
	/**
	 * @param length the length to set
	 */
	public void setLength(double length) {
		this.length = length;
	}
	/**
	 * @return the width
	 */
	public double getWidth() {
		return width;
	}
	/**
	 * @param width the width to set
	 */
	public void setWidth(double width) {
		this.width = width;
	}
	/**
	 * @return the height
	 */
	public double getHeight() {
		return height;
	}
	/**
	 * @param height the height to set
	 */
	public void setHeight(double height) {
		this.height = height;
	}
	
	public void display() {
		System.out.println("color="+getColor()+" length="+getLength()+" width="+ getWidth()+" height="+getHeight());		
	}
	public static void main(String[] args) {
		table table = new table("绿",1,1,1);
		table.display();
	}
}
package com.ambow.java20130917;

public class Student {
	private String name;
	private int age;
	private int banji;
	private String love;
	
	
	public Student(String name) {
		super();
		this.name = name;
	}




	public Student(String name, int age, int banji) {
		super();
		this.name = name;
		this.age = age;
		this.banji = banji;
	}




	public Student(String name, int age, int banji, String love) {
		super();
		this.name = name;
		this.age = age;
		this.banji = banji;
		this.love = love;
	}



	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}


	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}


	/**
	 * @return the age
	 */
	public int getAge() {
		return age;
	}


	/**
	 * @param age the age to set
	 */
	public void setAge(int age) {
		this.age = age;
	}


	/**
	 * @return the banji
	 */
	public int getBanji() {
		return banji;
	}


	/**
	 * @param banji the banji to set
	 */
	public void setBanji(int banji) {
		this.banji = banji;
	}


	/**
	 * @return the love
	 */
	public String getLove() {
		return love;
	}


	/**
	 * @param love the love to set
	 */
	public void setLove(String love) {
		this.love = love;
	}

	
	public void display() {
		System.out.println(name+" "+this.age+" "+banji+" "+this.love);
	}
}

package com.ambow.java20130917;

public class RectangleTest {
	public static void main(String[] args) {
		Rectangle rectangle = new Rectangle(1,1);
		rectangle.display();
	}
}

package com.ambow.java20130917;

public class NetTeacher extends Teacher {
	public NetTeacher(String myName, String myDept) {
		super(myName, myDept);
	}

	public void giveLesson() {
		System.out.println("启动 Visual Studio 2005");
		super.giveLesson();
	}
}

package com.ambow.java20130917;

public class JavaTeacher extends Teacher {

	public JavaTeacher (String myName, String myDept) {
		super(myName, myDept);
		}
		public void giveLesson(){
		System.out.println("启动 MyEclipse 6.0");
		super.giveLesson();
		}


}

package com.ambow.java20130917;

public class HomeworkTest {
	public static void main(String[] args) {
		Homework hs = new HomeworkStudent();
		Homework ht = new HomeworkTeacher();
		hs.collectHomework();
		ht.collectHomework();
	}
}

package com.ambow.java20130917;

public interface Homework {
	public void collectHomework();
}

package com.ambow.java20130917;

public class HomeworkTeacher implements Homework  {

	@Override
	public void collectHomework() {
		// TODO Auto-generated method stub
		System.out.println("老师收作业");
	}
	
}

package com.ambow.java20130917;

public class HomeworkStudent implements Homework {
	@Override
	public void collectHomework() {
		// TODO Auto-generated method stub
		System.out.println("学生收作业");
	}

}

package com.ambow.java20130917;

public class AnimalTest {
	public static void main(String[] args) {
		AnimalRabbit animalRabbit = new AnimalRabbit();
		animalRabbit.eat();
		animalRabbit.sleep();
		
		AnimalTiger animalTiger = new AnimalTiger();
		animalTiger.eat();
		animalTiger.sleep();
	}
}

package com.ambow.java20130917;

public class AnimalRabbit extends Animal {
	public void eat() {
		System.out.println("兔子吃草");
	}

}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值