fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static class Student {
  11. private final int uwecId;
  12. private String firstName;
  13. private String lastName;
  14. private double GPA;
  15.  
  16. public Student(int uwecId, String firstName, String lastName, double GPA) {
  17. this.uwecId = uwecId;
  18. this.firstName = firstName;
  19. this.lastName = lastName;
  20. this.GPA = GPA;
  21. }
  22.  
  23. public int getUwecId() {
  24. return uwecId;
  25. }
  26.  
  27. public String getFirstName() {
  28. return firstName;
  29. }
  30.  
  31. public String getLastName() {
  32. return lastName;
  33. }
  34.  
  35. public double getGPA() {
  36. return GPA;
  37. }
  38. }
  39.  
  40. static class StudentList extends ArrayList<Student>{
  41. @Override
  42. public String toString() {
  43. String outputString = "";
  44. for (Student student : this) {
  45. outputString += String.format("UWECStudent = uwecId: %d, name: %s %s, gpa: %.2f\n",
  46. student.getUwecId(), student.getFirstName(), student.getLastName(), student.getGPA());
  47. }
  48. return outputString;
  49. }
  50. }
  51.  
  52. public static void main (String[] args) throws java.lang.Exception {
  53.  
  54. Student s1 = new Student(123, "John", "Doe", 3.5);
  55. Student s2 = new Student(456, "Jane", "Doe", 4.0);
  56.  
  57. StudentList students = new StudentList();
  58. students.add(s1);
  59. students.add(s2);
  60.  
  61. System.out.println(students.toString());
  62. }
  63. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
UWECStudent = uwecId: 123, name: John Doe, gpa: 3.50
UWECStudent = uwecId: 456, name: Jane Doe, gpa: 4.00