Arraylist content expansion

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 559 Views - Last Post: 26 May 2020 - 01:18 PM Rate Topic: -----

#16 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3698
  • View blog
  • Posts: 16,952
  • Joined: 20-September 08

Re: Arraylist content expansion

Posted 25 May 2020 - 12:32 PM

Promising, but your class names should be singular: Student, Result
Also your classes are getting mingled which is not good.
Connecting Result (not sure about that name) and Student should really be done with some kind of UID - what would happen if two students were called 'John Smith'

Perhaps something like the following:
public class ExamResult {
    private int studentId;
    private int mark;
    private String description;

    public ExamResult() {
    }

    public ExamResult(int studentId, int mark, String description) {
        this.studentId = studentId;
        this.mark = mark;
        this.description = description;
    }

    public int getStudentId() {
        return this.studentId;
    }

    public int getMark() {
        return this.mark;
    }

    public String getDescription() {
        return this.description;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String toString() {
        return String.format("%s=%d,%s=%d,%s=%s", "studentId", studentId,
            "mark", mark, "description", description);
    }
}


This post has been edited by g00se: 25 May 2020 - 12:41 PM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#17 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Arraylist content expansion

Posted 25 May 2020 - 12:40 PM

These kind of comments are useless. The method name says the same thing
  //Add Student Records 
    private static void addStudent() {


     //Remove Studnet Records
    private static void removeStudentRecord() {



Start with the addStudent method.
What is it supposed to do?
How is it going to do it?

Currently the method does this:
gets name and age
creates a Students object to save the name and age
creates a Results object with the SAME DATA used to create the Students object
?? Why create object of another class with the same data?
Calls Register object's addStudent method with the above two objects?
What does that method do? Why does it need two objects with the same data?

This post has been edited by NormR: 25 May 2020 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

#18 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Arraylist content expansion

Posted 25 May 2020 - 01:32 PM

View Postg00se, on 25 May 2020 - 12:32 PM, said:

Promising, Student, Result
Also your classes are getting mingled which is not good.
Connecting Result (not sure about that name) and Student should really be done with some kind of UID - what would happen if two students were called 'John Smith'

Perhaps something like the following:
public class ExamResult {
    private int studentId;
    private int mark;
    private String description;

    public ExamResult() {
    }

    public ExamResult(int studentId, int mark, String description) {
        this.studentId = studentId;
        this.mark = mark;
        this.description = description;
    }

    public int getStudentId() {
        return this.studentId;
    }

    public int getMark() {
        return this.mark;
    }

    public String getDescription() {
        return this.description;
    }

    public void setStudentId(int studentId) {
        this.studentId = studentId;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String toString() {
        return String.format("%s=%d,%s=%d,%s=%s", "studentId", studentId,
            "mark", mark, "description", description);
    }
}



Quote

but your class names should be singular:

Thank you for your observation.

Quote

Connecting Result (not sure about that name) and Student should really be done with some kind of UID - what would happen if two students were called 'John Smith'


great idea, This is my first program to challenge myself on what i have learnt so far, I believe I can still clean up the code over time. But i will consider your suggestion. If i do it this way, How do i associate the register details with Result.

I believe you now have ideas of what am trying to achieve. instead of me having two classes with Student and Result; is it possible to have one class of Student and make Result reference to Student. But my worry is that at the point of registering, there will be no data for result score and remark. How do i create those data for the object result after Exam?

This post has been edited by seyidesh: 25 May 2020 - 01:42 PM

Was This Post Helpful? 0
  • +
  • -

#19 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Arraylist content expansion

Posted 25 May 2020 - 01:50 PM

Quote

at the point of registering, there will be no data for result score and remark

When is a student supposed to be registered?
Before or after the score is available?
If the registration is done after the score is available, then all the needed data can be collected at registration time.
If registration is done before the score is available, the student record will be available in a list of registered students that can be searched and their scores added.

This post has been edited by NormR: 25 May 2020 - 01:52 PM

Was This Post Helpful? 0
  • +
  • -

#20 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Arraylist content expansion

Posted 25 May 2020 - 02:00 PM

View PostNormR, on 25 May 2020 - 01:50 PM, said:

Quote

at the point of registering, there will be no data for result score and remark

When is a student supposed to be registered?
Before or after the score is available?
If the registration is done after the score is available, then all the needed data can be collected at registration time.
If registration is done before the score is available, the student record will be available in a list of registered students that can be searched and their scores added.


Quote

Before or after the score is available?

The score is available after Registration. The student will be checked if he has register before taking the exam. I only to know to write the code to include the scores that was gotten to already store registration.

You just hit me where am pained. I have an issue writing the code that will add the score to the registered student list, Maybe if you run the code i posted earlier, you will understand better.

This post has been edited by seyidesh: 25 May 2020 - 02:03 PM

Was This Post Helpful? 0
  • +
  • -

#21 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Arraylist content expansion

Posted 25 May 2020 - 02:04 PM

Quote

code that will add the score to the registered student list

Can you describe the steps the program needs to take to do that?
Assume that there are Student records in the students list.
Given a score for one of the students, how would the code find the record for the student so his score could be updated? Do the students all have unique names or how would the program find the correct student record to update?

Quote

run the code i posted earlier,

I think that code needs to be rewritten to solve the problem. Don't try a simple fix.

This post has been edited by NormR: 25 May 2020 - 02:05 PM

Was This Post Helpful? 0
  • +
  • -

#22 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Arraylist content expansion

Posted 25 May 2020 - 02:19 PM

View PostNormR, on 25 May 2020 - 02:04 PM, said:

Quote

code that will add the score to the registered student list

Can you describe the steps the program needs to take to do that?

Assume that there are Student records in the students list.
Given a score for one of the students, how would the code find the record for the student so his score could be updated? Do the students all have unique names or how would the program find the correct student record to update?

Quote

run the code i posted earlier,

I think that code needs to be rewritten to solve the problem. Don't try a simple fix.


Quote

Can you describe the steps the program needs to take to do that?

Here are the steps,

The program is to examine student but before the student is examined, the student needs to register.

Student Registration -> Exam Room, but before student enter the Exam room (Student is checked to confirm he has registered) -> take the exam - > Store the Exam result under the checked Student information -> print out student results.

Quote

how would the code find the record for the student so his score could be updated? Do the students all have unique names or how would the program find the correct student record to update?


for now I am using Surname to check, I will include Student ID once am able to resolve this challenges
Was This Post Helpful? 0
  • +
  • -

#23 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Arraylist content expansion

Posted 25 May 2020 - 02:28 PM

Quote

student needs to register.

What class is that data kept in?
Where are instances of that class stored?

Quote

confirm he has registered)

That could look at where the above saves the instances of the student's data

Quote

Store the Exam result under the checked Student information

That could be stored in the student's object from the first step.

Quote

using Surname to check

the student class could have a method that tests for a match.

This post has been edited by NormR: 25 May 2020 - 02:30 PM

Was This Post Helpful? 0
  • +
  • -

#24 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Arraylist content expansion

Posted 26 May 2020 - 01:18 PM

Thank you guys, Problem resolved, Everything works fine now
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2