美文网首页
7月16代码总量草稿

7月16代码总量草稿

作者: 玄薛烨 | 来源:发表于2016-07-16 20:18 被阅读20次

    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());

    }

    }

    相关文章

      网友评论

          本文标题:7月16代码总量草稿

          本文链接:https://www.haomeiwen.com/subject/wzeujttx.html