7月16代码总量草稿

package code;

public class Animal {

private  String name;

private double height;

private  String color;

public Animal(String  name){

this.name=name;

};

public Animal(String name, double height, String color){

this.name=name;

this.height=height;

this.color=color;

}

public void voice(){};

public String getName(){

return this.name;

}

public double getHeight(){

return this.height;

}

public String getColor(){

return this.color;

}

public void hunter(){System.out.println(this.name+" kill some animal");}

public static void main(String[] args) {

}

}

public class Cat extends Animal {

public Cat(String name,String color, double height){

super(name,height,color);

}

public Cat(String name){

super(name);

}

public void hunter(){

System.out.println("Kill some mouse");

}

}

public class textAnimal {

public static void main(String[] args) {

Dog dog=new Dog("大黄");

Cat cat=new Cat("小红");

dog.hunter();

cat.hunter();

Animal animal=new Animal("四脚动物");

animal.hunter();

doHunter(cat);

}

public static void doHunter(Animal  animal){

if(animal instanceof Dog){

System.out.println("这是一条可爱的狗");

Dog d = (Dog)animal;

}else{

System.out.println("这不是狗");

}

animal.hunter();

}

}



public class Dog extends Animal{

public Dog(String name,String color, double height){

super(name,height,color);

}

public Dog(String name){

super(name);

}

public void hunter(){

System.out.println("Kill some animal");

}

}



public class Circle {

private double radius=1.0;

private String color;

public Circle(){};

public Circle(double radius){

this.radius=radius;

}

public Circle(double radius, String color){

this.radius=radius;

this.color=color;

}

public void setColor(String color){

this.color=color;

}

public void setRadius(double radius){

this.radius=radius;

}

public double getRadius(){

return this.radius;

}

public double getArea(){

return this.radius*this.radius*Math.PI;

}

public String getColor(){

return this.color;

}

public double getCircumference(){

return 2*Math.PI*this.radius;

}

public  void toString(String color, double radius){

System.out.println("Circle[radius="+this.radius+",color="+this.color+"]");

}

public static void main(String[] args) {

Circle c=new Circle();

Circle c2=new Circle(9);

Circle c3=new Circle(1,"red");

System.out.println(c2.getRadius());

System.out.println(c2.getArea());

System.out.println(c3.getColor());

c3.toString("红",16);

System.out.println("圆的周长为:");

System.out.println(c3.getCircumference());

}

}



public class Employee {

private int id;

private String firstName;

private String lastName;

private int salary;

public Employee(){};

public Employee(int id , String firstName, String lastName, int salary){

this.firstName=firstName;

this.lastName=lastName;

this.id=id;

this.salary=salary;

}

public int getID(){

return this.id;

}

public String getFirstName(){

return this.firstName;

}

public String getLastName(){

return this.lastName;

}

public String getName(){

return this.firstName+ " "+this.lastName;

}

public int getSalary(){

return this.salary;

}

public void setSalary(int salary){

this.salary=salary;

}

public int getAnnualSalary(){

return 12*this.salary;

}

public int raiseSalary(int percent){

this.salary=(int)salary*(1+(double)percent/100);

return salary;

}

public String toString(){

String str2="Employee[id="+this.id+",name="+getName()+",Salary= "+this.salary+"]";

return str2;

}

}



public class testEmployee {

public static void main(String[] args) {

Employee employee=new Employee(01,"kewu","liao",100000);

System.out.println(employee.toString());

System.out.println(employee.raiseSalary(50));

System.out.println(employee.getSalary());

employee.setSalary(1000000);

System.out.println(employee.toString());

}

}

public class Rectangle {

private float length=1.0f;

private float width=1.0f;

public Rectangle(){}

public Rectangle(float length,float width){

if(length>0&&width>0){

this.length=length;

this.width=width;

}

}

public float getLength(){

return this.length;

}

public void setLength(float length){

if(length>0){

this.length=length;

}

this.length=length;

}

public float getWidth(){

return this.width;

}

public void setWidth(float width){

if(width>0){

this.width=width;

}

}

public double getArea(){

return this.length*this.width;

}

public double getPerimeter(){

return this.length*this.width;

}

public String toString(){

String str2="Rectangle[length="+this.length+",width="+this.width+"]";

return str2;

}

}



public class rectangleTest {

public static void main(String[] args) {

Rectangle rectangle=new Rectangle(-1,-2);

Rectangle rectangle2=new Rectangle(18,10);

System.out.println("输出长方形1的长:");

System.out.println(rectangle.getLength());

System.out.println("输出长方形1的宽:");

System.out.println(rectangle.getWidth());

System.out.println("输出长方形1的:");

System.out.println(rectangle2.toString());

System.out.println(rectangle2.getLength());

System.out.println(rectangle2.getWidth());

System.out.println("长方形的周长:");

System.out.println(rectangle2.getPerimeter());

System.out.println("长方形的面积:");

System.out.println(rectangle2.getArea());

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,958评论 18 399
  • SwiftDay011.MySwiftimport UIKitprintln("Hello Swift!")var...
    smile丽语阅读 9,251评论 0 6
  • 小编费力收集:给你想要的面试集合 1.C++或Java中的异常处理机制的简单原理和应用。 当JAVA程序违反了JA...
    八爷君阅读 10,195评论 1 114
  • 用感情做事的人,经常会受到感情的伤害,甚至会引发抱怨、嗔恨、愤怒等等不良的心理反应。为什么用感情做事情,会受到感情...
    一个人的独行阅读 3,311评论 0 1
  • 1、横切 连接点:应用通知的所有点 通知:切面是什么及何时使用 切点:通知被应用的具体位置(哪些连接点) 切面:通...
    宇宙超人喵学长阅读 1,371评论 0 0