자바 패키지 예제

2101 단어
package com.microhup;

import java.util.Scanner;

/**
 * Project: sapp
 * Created by leiding on 2015-11-26.
 * Copyright (c) 2015 Microhup.ALL right reserved.
 */
public class Print {
    public static void main(String[] args){
        Dog d = new Dog();
        Scanner input = new Scanner(System.in);
        String defName = "gg";
        String defSex = "f";
        int defAge = 1;
        int defHeslth = -1;

       // System.out.println("       ");
        d.setName(defName);
       // System.out.println("        ");
        d.setSex(defSex.charAt(0));
       // System.out.println("        ");
        d.setAge(defAge);
       // System.out.println("         ");
        d.setHeslth(defHeslth);
        d.print();

    }
}
public class Dog {
    private String name;
    private int heslth;
    private char sex;
    private int age;
//  
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHeslth() {
        return heslth;
    }

    public void setHeslth(int heslth) {
        if(heslth<=0){
            this.heslth = 60;
            return;
        }else{
            this.heslth = heslth;
        }
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public void print(){
        String s = "  :"+name+"\t  :"+sex+"\t  :"+age+"\t  :"+heslth;
        System.out.println(s);
    }
}

좋은 웹페이지 즐겨찾기