老师出了道题,(1)编写一个Java程序,包含三个类,分别是主类、父类和子类。
(2)父类不少于2个变量1个方法,子类不少于1个变量1个方法。
(3)主类中包含创建对象的功能、调用方法的功能、输出功能。
(4)每个方法中至少包括一个参数。
(5)需要在至少一个方法中出现Return返回语句。
(6)程序不少于30行。
(7)程序需要能够运行。
(8)类的构造可以选自社会生活中的任何事物。
(1)设置循环语句的程序可优先加分。
(2)设置方法重载的程序可优先加分。
想来想去都没头绪,求解啊,肿么写啊

解决方案 »

  1.   

    真想问你学多久java了 如果是半个学期的话 楼主可以不用学java了 
      

  2.   

    /*
    作者:雪狼
    功能:this的必要性
    */
    public class Demo3
    {
    public static void main(String []args)
    {     
     /*Dog dog1=new Dog(2,"大黄");
             Person p1=new Person(dog1,23,"郭德纲");
     Person p2=new Person(dog1,24,"刘谦");
     p1.showInfo();
     p1.dog.showInfo();*/
    // int total=0;
     Child ch1=new Child(3,"小哈");
     ch1.joinGame();
     //total++;r
     Child ch2=new Child(4,"小河");
     ch2.joinGame();
     //total++;
             Child ch3=new Child(3,"淡定");
     ch3.joinGame();
    // System.out.println("共有人="+ch2.total);
    System.out.println("共有人"+Child.total);
    }
    }
    //定义小孩类
    class Child
    {
               int age;
       String name;
       //total 静态变量,因此可以被任何对象访问
       //声明静态变量給前面加 static
       static int total=0;
       public Child(int age,String name)
    {
       this.age=age;
       this.name=name;
       }
       public void joinGame()
    {
       total++;
       System.out.println("有一个小孩加入了");
       }
    }
    //定义一个人类
    class Person
    {
    int age;
    String name;
    Dog dog;//引用类型的成员变量
    //构造方法
    public Person(Dog dog,int age,String name)
    {    //this属于具体的对象 自动赋予(隐藏起来) this.age=age;
    this.name=name;
    this.dog=dog;
    }
    //成员方法
    public void showInfo()
    {
    System.out.println("人名是:"+this.name);
    }
    }
    class Dog
    {
    int age;
    String name;
    public Dog(int age,String name)
    {
    this.age=age;
    this.name=name; }
    //显示狗名
    public void showInfo()
    {
    System.out.println("够名叫"+name);
    }
    }
      

  3.   

    //父类
    public abstract class Account {
    String accountId;//账号
    String accontName;//姓名
    public Account(String id,String name){
    this.accountId=id;
    this.accontName=name;
    }
    double money;//余额
    //存款
    public abstract double doposit(double money);
    //取款
    public abstract double withdraw(double money);
    public String toString(){
    return "账号:"+this.accountId+"姓名:"+this.accontName+"余额:"+this.money;
    }
    }
    //子类
    public class SavingAccount extends Account{
    public SavingAccount(String id,String name){
    super(id,name);
    }
    //存款
    public double doposit(double money){
        return this.money=this.money+money;
    };
    //取款
    public double withdraw(double money){
    if(this.money>money){
    return this.money=this.money-money;
    };
    }
    }
    //主类
    public class accountTest {
    public static void main(String[] args) {
    SavingAccount t=new SavingAccount("001","zhangsan");
    t.doposit(100.0);//调用存款方法
    t.withdraw(50);//调用取款方法
    System.out.println(t.toString());//显示账户信息
    }
    }
      

  4.   

    这个lz要自己做了才有体会丫
    看看ls写的东西,自己仿着写一个吧