Example #1
0
  public static void main(String[] args) {
    Colleges c = new Colleges();
    Student s = new Student();
    Teacher t = new Teacher();
    c.setName("***科技学院");
    c.setNum(16000);
    c.setArea(800);

    s.setName1("秦*盛");
    s.setGrade("测绘B111");
    s.setMajor("建筑工程学院");

    t.setName("王老师");
    t.setCurriculum("Java 编程");

    System.out.println(c.getName() + " 有 " + c.getNum() + "名学生" + "占地面积" + c.getArea() + "亩");

    System.out.println(t.getName() + "在" + c.getName() + "教授" + t.getCurriculum());

    System.out.println(
        s.getName1()
            + "就读于"
            + s.getMajor()
            + s.getGrade()
            + "在上"
            + t.getName()
            + "的"
            + t.getCurriculum());
  }
 @Test
 public void gradevalueTest() {
   System.out.println("StudentTest");
   Student instance = new Student();
   double expResult = 89.3;
   instance.setGrade(expResult);
   double result = instance.getGrade();
   assertEquals(expResult, result, 0.0);
 }
  public static void main(String arg[]) {
    Person p = new Person();
    p.setName("John Doe");

    // Student inherits the methods and behavior from the Person class
    Student s = new Student();
    s.setName("Jane Doe");

    s.setSchool("A Fictional School");
    s.setGrade(10);

    rollCall(p);
    rollCall(s);
  }
 /** Test of toString method, of class Student. */
 @Test
 public void testToString() {
   try {
     System.out.println("toString");
     Student instance = new Student();
     instance.setName("Bill Smith");
     instance.setId("c0123456");
     instance.setGender("male");
     instance.setGrade(89.3);
     String jsonString = instance.toString();
     JSONObject result = (JSONObject) new JSONParser().parse(jsonString);
     JSONObject expResult =
         (JSONObject)
             new JSONParser()
                 .parse(
                     "{\"name\":\"Bill Smith\",\"id\":\"c0123456\",\"gender\":\"male\",\"grade\":\"89.3\"}");
     assertEquals(expResult, result);
   } catch (ParseException ex) {
     System.err.println("Invalid JSON Format");
     fail("Invalid JSON Format");
   }
 }