@Test public void testsameiddifferentnameEquals() { System.out.println("equals"); Student instance1 = new Student(); instance1.setName("Ranjith"); instance1.setId("c0663421"); Student instance2 = new Student(); instance2.setName("surya"); instance2.setId("c0663421"); assertFalse(instance1.getName().equals(instance2.getName())); }
public static void main(String args[]) { Student obj1 = new Student(); obj1.setId("14-34234-2"); obj1.showInfo(); Student obj2 = new Student("RAIYAN", "14-28958-1", "CSE", 2.75f); obj2.showInfo(); obj2.setId("15-28958-1"); System.out.println(obj2.getId()); }
/** Test of equals method, of class Student. */ @Test public void testEquals() { System.out.println("equals"); Student instance1 = new Student(); instance1.setName("Ranjith"); instance1.setId("c0663421"); Student instance2 = new Student(); instance2.setName("Ranjith"); instance2.setId("c0663421"); assertEquals(instance1, instance2); }
private void addStudent(StudentDirectory dir2, int i) { String id = "" + i; Student student = new Student(id); student.setId(id); student.addCredits(i); dir.add(student); }
public Student mapRow(ResultSet rs, int rowNum) throws SQLException { Student student = new Student(); student.setId(rs.getInt("id")); student.setName(rs.getString("name")); student.setAge(rs.getInt("age")); return student; }
@Test public void testStudent() { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml"); StudentService studentService = (StudentService) ac.getBean("studentService"); Student student = new Student(); student.setId(1); student.setName("Who am I"); studentService.addStudent(student); }
@POST @Path("/students/") public Response addStudent(Student s) { System.out.println("Entered inside the addcustomer method with name" + s.getName()); s.setId(initid++); Students.put(s.getId(), s); Response r = Response.ok().build(); return r; }
@Test public void idvalueTest() { System.out.println("StudentTest"); Student instance = new Student(); String expResult = "c0123456"; instance.setId(expResult); String result = instance.getId(); assertEquals(expResult, result); }
public static ScoreMenu[] loadFile() { MainWindow.initDataFile(SCORE_MENU_FILE); DataInputStream input; Course course; Class tempClass; Student student; int[] testTime; long[] id; float[] score; ScoreMenu[] scoreMenu = new ScoreMenu[20]; int count = 0; try { input = new DataInputStream(new FileInputStream(SCORE_MENU_FILE)); while (input.available() > 0) { if (count >= scoreMenu.length) { ScoreMenu[] temp = new ScoreMenu[scoreMenu.length * 2]; for (int i = 0; i < scoreMenu.length; i++) temp[i] = scoreMenu[i]; scoreMenu = temp; } tempClass = new Class(); tempClass.setGrade(input.readInt()); tempClass.setMajor(input.readUTF()); tempClass.setClassNumber(input.readInt()); tempClass.setStudentNumber(0); int num = input.readInt(); for (int i = 0; i < num; i++) { student = new Student(); student.setId(input.readLong()); student.setName(input.readUTF()); tempClass.addStudent(student); } course = new Course(); course.setId(input.readUTF()); course.setName(input.readUTF()); course.setCredit(input.readFloat()); course.setPeriod(input.readInt()); testTime = new int[5]; for (int i = 0; i < 5; i++) testTime[i] = input.readInt(); num = input.readInt(); id = new long[num]; score = new float[num]; for (int i = 0; i < num; i++) id[i] = input.readLong(); for (int i = 0; i < num; i++) score[i] = input.readFloat(); scoreMenu[count] = new ScoreMenu(tempClass, course, testTime, num, id, score); count++; } input.close(); return scoreMenu; } catch (Exception e) { return null; } }
public static void main(String args[]) throws IllegalAccessException { ExportExcel<Student> export = new ExportExcel<Student>(); List<Student> list = new ArrayList<Student>(); Student stu = new Student(); stu.setId(123); stu.setDate(new Date()); stu.setName("liquing"); Student stu1 = new Student(); stu1.setId(1231); stu1.setDate(new Date()); stu1.setName("刘海"); Student stu2 = new Student(); stu2.setId(1231); stu2.setDate(new Date()); stu2.setName("liquing1"); list.add(stu); list.add(stu1); list.add(stu2); export.createHeader(list); FileOutputStream out = null; try { out = new FileOutputStream("e:\\um.xls"); export.hw.write(out); } catch (Exception e) { // TODO: handle exception } finally { if (out != null) { try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
public static ScoreMenu queryFromFile(Class classes, Course courses) { MainWindow.initDataFile(SCORE_MENU_FILE); DataInputStream input; Class tempClass = new Class(); Student student; Course course = new Course(); int[] testTime = new int[5]; int numberOfAttendTestStudent; long idOfStudents[]; float scoreOfTest[]; try { input = new DataInputStream(new FileInputStream(SCORE_MENU_FILE)); while (input.available() > 0) { tempClass.setGrade(input.readInt()); tempClass.setMajor(input.readUTF()); tempClass.setClassNumber(input.readInt()); int studentNumber = input.readInt(); tempClass.setStudentNumber(0); for (int i = 0; i < studentNumber; i++) { student = new Student(); student.setId(input.readLong()); student.setName(input.readUTF()); tempClass.addStudent(student); } course.setId(input.readUTF()); course.setName(input.readUTF()); course.setCredit(input.readFloat()); course.setPeriod(input.readInt()); for (int i = 0; i < 5; i++) testTime[i] = input.readInt(); numberOfAttendTestStudent = input.readInt(); idOfStudents = new long[numberOfAttendTestStudent]; scoreOfTest = new float[numberOfAttendTestStudent]; for (int i = 0; i < numberOfAttendTestStudent; i++) idOfStudents[i] = input.readLong(); for (int i = 0; i < numberOfAttendTestStudent; i++) scoreOfTest[i] = input.readFloat(); if ((classes.equals(tempClass)) && (courses.equals(course))) { input.close(); return new ScoreMenu( tempClass, course, testTime, numberOfAttendTestStudent, idOfStudents, scoreOfTest); } } input.close(); return null; } catch (Exception e) { return null; } }
private void init() { String name = "manikanta"; for (int i = 5; i >= 0; i--, initid++) { Student s = new Student(); s.setId(initid); s.setName(name.substring(0, i + 4)); s.setContact(98988989); Address ad = new Address(); s.setAddress(ad); Students.put(initid, s); } // Student s=new Student(); // s.setId(initid); // s.setName("Mani"); // Students.put(s.getId(), s); }
public ArrayList<Course> initialCourseList() { ArrayList<Course> courseList = new ArrayList<Course>(); try { br = new BufferedReader(new FileReader("data/course.txt")); while ((line = br.readLine()) != null) { String[] split = line.split(" "); Course newCourse = new Course(); newCourse.setCourseId(split[0]); newCourse.setCourseName(split[1]); newCourse.setCompulsory(split[2].equals("true") ? true : false); newCourse.setPeriod(Integer.parseInt(split[3])); newCourse.setScore(Integer.parseInt(split[4])); User newTeacher = new Teacher(); newTeacher.setId(split[5]); newTeacher.setType("teacher"); newTeacher.setPassword(null); newCourse.setTeacherUser(newTeacher); newCourse.setTime(split[6]); newCourse.setClassroom(split[7]); int i = 8; ArrayList<User> list = new ArrayList<User>(); while (i < split.length) { Student newStudent = new Student(); newStudent.setId(split[i]); newStudent.setType("student"); newStudent.setPassword(null); list.add(newStudent); i++; } newCourse.setAssistStudentList(list); courseList.add(newCourse); } } catch (IOException ex) { ex.printStackTrace(); } return courseList; }
public ArrayList<User> initialStudentList() { ArrayList<User> studentList = new ArrayList<User>(); try { br = new BufferedReader(new FileReader("data/student.txt")); while ((line = br.readLine()) != null) { String[] split = line.split(" "); Student newStudent = new Student(); newStudent.setId(split[0]); newStudent.setName(split[1]); newStudent.setPassword(split[2]); newStudent.setType("student"); studentList.add(newStudent); } } catch (IOException ex) { ex.printStackTrace(); } return studentList; }
/** 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"); } }
public boolean saveToFile() { MainWindow.initDataFile(SCORE_MENU_FILE); DataInputStream input; DataOutputStream output; Class tempClass = new Class(); Student student = new Student(); Course course = new Course(); int[] testTime = new int[5]; int numberOfAttendTestStudent; long idOfStudents[]; float scoreOfTest[]; try { input = new DataInputStream(new FileInputStream(SCORE_MENU_FILE)); while (input.available() > 0) { tempClass.setGrade(input.readInt()); tempClass.setMajor(input.readUTF()); tempClass.setClassNumber(input.readInt()); int studentNumber = input.readInt(); tempClass.setStudentNumber(0); for (int i = 0; i < studentNumber; i++) { student.setId(input.readLong()); student.setName(input.readUTF()); } course.setId(input.readUTF()); course.setName(input.readUTF()); course.setCredit(input.readFloat()); course.setPeriod(input.readInt()); for (int i = 0; i < 5; i++) testTime[i] = input.readInt(); numberOfAttendTestStudent = input.readInt(); idOfStudents = new long[numberOfAttendTestStudent]; scoreOfTest = new float[numberOfAttendTestStudent]; for (int i = 0; i < numberOfAttendTestStudent; i++) idOfStudents[i] = input.readLong(); for (int i = 0; i < numberOfAttendTestStudent; i++) scoreOfTest[i] = input.readFloat(); if ((this.classOfScoreMenu.equals(tempClass)) && (this.course.equals(course))) { input.close(); return false; } } input.close(); output = new DataOutputStream(new FileOutputStream(SCORE_MENU_FILE, true)); output.writeInt(this.classOfScoreMenu.getGrade()); output.writeUTF(this.classOfScoreMenu.getMajor()); output.writeInt(this.classOfScoreMenu.getClassNumber()); int num = this.classOfScoreMenu.getStudentNumber(); output.writeInt(num); Student[] students = this.classOfScoreMenu.getStudents(); for (int i = 0; i < num; i++) { output.writeLong(students[i].getId()); output.writeUTF(students[i].getName()); } output.writeUTF(this.course.getId()); output.writeUTF(this.course.getName()); output.writeFloat(this.course.getCredit()); output.writeInt(this.course.getPeriod()); for (int i = 0; i < 5; i++) output.writeInt(this.testTime[i]); output.writeInt(this.numberOfAttendTestStudent); for (int i = 0; i < this.numberOfAttendTestStudent; i++) output.writeLong(this.idOfStudents[i]); for (int i = 0; i < this.numberOfAttendTestStudent; i++) output.writeFloat(this.scoreOfTest[i]); output.close(); return true; } catch (Exception e) { return false; } }
public void add() { // DAO save the add item.setId(list.isEmpty() ? 1 : list.get(list.size() - 1).getId() + 1); list.add(item); item = new Student(); }
public static void main(String[] args) { Module sw = new Module("Software Workshop", "Jon Rowe"); System.out.println(sw); System.out.println(sw.getName()); System.out.println(sw.getLecturer()); System.out.println("changing lecturer"); sw.setLecturer("Martin Escardo"); System.out.println(sw); Student alf = new Student("Alfred Smith", 12345); Student bob = new Student("Bob Mascheranas", 24680); System.out.println(alf); System.out.println(alf.getName()); System.out.println(alf.getId()); System.out.println("changing id"); alf.setId(54321); System.out.println(alf); alf.setModule(0, sw); alf.setModule(1, new Module("Foundations", "Dan Ghica")); alf.setModule(2, new Module("Intro to AI", "Volker Sorge")); bob.setModule(0, sw); bob.setModule(1, new Module("Foundations", "Dan Ghica")); bob.setModule(2, new Module("Intro to AI", "Volker Sorge")); TutorGroup TG = new TutorGroup("Nick Hawes"); System.out.println("Does sw = sw?"); System.out.println(sw.equals(sw)); System.out.println("Is alf on sw?"); System.out.println(alf.onModule(sw)); System.out.println("Check: TutorGroup toString()"); System.out.println(TG); System.out.println("Check: TutorGroup getStudents()"); System.out.println(TG.getStudents()); System.out.println("Check: TutorGroup addStudent()"); TG.addStudent(bob); System.out.println(TG.getStudents()); System.out.println("Check: TutorGroup setTutor()"); TG.setTutor("Achim Jung"); System.out.println(TG); System.out.println("Check: TutorGroup getTutor()"); System.out.println(TG.getTutor()); // System.out.println(alf.getModule(1)); for (int i = 0; i < 3; i++) { System.out.println(alf.getModule(i)); } }