程序改错题,请指出指定位置语句的错误。
  Class Book{       //6:
public String name;
private float price;
initBook(String n,float p){          //1:
      name=n;price=p;}
public void setPrice(float p){
    this.price=p   }          //2:public class useBook{
  public void main(String arg[]){
       Book b=new Book(“Java2”,52.5f);    //3:
       System.out.print(“name”+name);     //4:
       System.out.print(“\tprice:”+price);    //5:
   }      //12:
编程题
定义一个时钟类—Clock,它包括三个整型变量分别表示小时、分钟和秒,一个成员方法show()用于显示时钟对象的时间信息(显示格式:”时间为15:20:35”)。定义描述学生的类—Student,成员变量:学生姓名(name)、年龄(age) 和学生编号(整数型,静态成员);output成员方法用于输出学生信息(信息格式:“编号:1,姓名:张山,年龄:25”),构造方法初始化3个成员变量。如:Student s1=new Student(“张山”,25)
谢谢各位,我是菜鸟。

解决方案 »

  1.   

    //6 "Class"应小写 class
    //1 应为Book(X,X)把init去掉
    //2 少分号
    //3 去f
    //4 b.name
    //5 price为私有变量
    //12 少分号
      

  2.   

    改成如下:
    class Book
    {      
       public String name;
       public  float price;
           Book(String n,float p)
           {        
             name=n;price=p;
           }
          public void setPrice(float p)
          {
              this.price=p;  
          }         
    }public class useBook
    {
      public static void main(String arg[])
      {
           Book b=new Book("Java2",52.5f);    
           System.out.print("name"+b.name);    
           System.out.print("\tprice:"+b.price);    
      }  
    }
      

  3.   

    题目也许对于楼主来说有难度,不过从编程来看,非常easy,所以建议楼主多看看面向对象的书,这些是最简单的面向对象的基础,书上一般都会有一些比较简单的例子,有些应该和这些非常类似。
      

  4.   

    Clock.java
    public class Clock {
    private int h; private int m; private int s; public Clock(int h, int m, int s) {
    this.h = h;
    this.m = m;
    this.s = s;
    } public void show() {
    System.out.println("时间为" + h + ":" + m + ":" + s);
    } public static void main(String[] arge) {
    Clock clock = new Clock(12, 45, 20);
    clock.show();
    }
    }
    Student那个和这个差不多替换参数和方法名就可以
      

  5.   

    //Student.java
    /*  定义描述学生的类—Student,成员变量:学生姓名(name)、年龄(age) 和学生编号(整数, 静态成员);output成员方法用于输出学生信息(信息格式:“编号:1,姓名:张山,年龄:25”),构造方法初始化3个成员变量。如:Student s1=new Student(“张山”,25)
    */public class Student {
    private String name; private int age; private static int No = 1; public Student(String name, int age) {
    this.name = name;
    this.age = age;
    this.No++;
    } public void output() {
    System.out.println("编号:" + No + "姓名:" + name + "年龄:" + age);
    } public static void main(String[] arge) {
    Student s1=new Student(“张山”,25);
    s1.output();
    }
    } 不知道行不行,照着楼上的大哥的代码写的,我也是新手,一起学习,楼下的,不对的地方给我说声阿,先谢谢了