Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Individual array of grades for every new student

 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Im making Teacher Managing application.
I have got 3 types of objects: Teacher, Student, Lesson
Teacher can create Lesson object. Every Lesson object is stored in ArrayList.
Teacher can add Student object to Lesson (register him).
Teacher can give grades for every specific Student from every specific Lesson-and this is my problem.
I have got no idea how can I connect Student with Subjects and give him individual array with grades from it.
In my head it looks like this: `` Example.

"John Smith" (Student object) is registered to "Math", "Chemistry", "Philosopy", "Biology" (Lesson objects)

   From "Math" he have got [1, 2, 4] grades,  
   From "Chemistry" he have got [5] grade,  
   From "Philosophy" he have got [2, 3, 4, 4] grades,  
   From "Biology" he have got [1,2,3,4,5] grades.
All grades ale given by teacher, he can give him another one -so I think its going to be ArrayList of grades in every Lesson object. But how the Student can have individual grades from specific Lesson? With one Student is simple-Lesson object would have in class fields ArrayList grades but what is the solution if I would have for example-another 10, 100, 1000 students and all of them have to have individual ArrayList with grades ( for example: JohnSmith.Biology.[1,2,3], JasmineLaw.Biology.[2,2,3], PeterSchmitd.Biology.[5,5,5])
How can I connect many Students object with many Lessons with his own, individual array with grades? I cant use any external database to hold this data. Plain Java.
 
Carey Brown
Saloon Keeper
Posts: 7393
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does Lesson have any other attributes other than name?

You could have
The choice isn't exactly clear because it's not a straight forward has-a relationship. The relationship is more like a many-to-many relationship which would mean that you'd end up with a Grades class that has the Student and the Lesson as keys and containing a List<Integer> as its value.
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Does Lesson have any other attributes other than name?

You could have
The choice isn't exactly clear because it's not a straight forward has-a relationship. The relationship is more like a many-to-many relationship which would mean that you'd end up with a Grades class that has the Student and the Lesson as keys and containing a List<Integer> as its value.



In the begining I want to say thank you for answer!
Lesson its just a name, nothing else.
I think the idea with Grades class sounds great!
I never used thing like Map, I will read documentation about it but first I have got question about an overall idea.
Its going to look like this: Map<K1,K1,V>
where
K1-Student (for example ArrayList<Student> -cause its many of them)
K2-Subject
V-List<Integer>
?
So my Grades class that is holding that kind of map will generate individual List<Integer> for every Students and will connect it with specific Lesson?
One "record" of map in Grades will be like one color line:

So its like Many to one to Many relation?
One Grades object is generated for list of Students, specific Lesson and List<Integer> grades?
Or its more like:

So one Grade object is generated for specific Student in specific Lesson with List<Integer> grades?
In this case every Student will have Grades object for every Lessons he is registered to. So the Student class need to hold ArrayList<Grades>.
So map will look like this: Map<K1: Student(one object),K2 :Lesson(one object),V : List<Integer>> ?

For many to one to many :
Lets make some pseudocode, I want this to be clear for me:

And accessing this from Teacher side (for purpose of giving a grade) will look like this


EDIT no5:
I just checked-theoretically I cant have Map with 2 keys and 1 value but in practice I can create another class, for example GradesKey that is going to hold specific Student and specific Lesson as a class field. So this way it will look like this:
Grades<GradesKey, List<Integer>
So one GradesKey wil be linked to specific Student that is registered to specific Lesson and accessing will be kinda nested-cause to give any grade I need to access Grades->GradesKey->Student->studentID
..........................................->Lesson->lessonName
To access I need to connect with 2 branches that sprout up from GradesKey. Im not sure if I understand everything clear.
 
Carey Brown
Saloon Keeper
Posts: 7393
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:If Lesson is just a key of lessonName, then I'd go with option 1. MUCH simpler.


I tried few approach for this problem and I have got no idea how to implement this solution.
I made some short "demo version" of my console app to find some clear answer-but still I cant make head or tail of it. In my "big project" all data is stored in static ArrayList (Teacher, Lesson and Student objects) that why in this simple approach I added also ArrayLists.
Hastebin hosting: https://hastebin.com/ajitutabuv.csharp
Pastebinh hosting: https://pastebin.com/sw1PVqcm
So, theoretical -when I create Lesson object-it create also in it Map called grades that hold: Student as a key and as a value of it- ArrayList<Integer>.
So adding Student to specific Lesson and giving him a grades should be like this:
ADDING TO SUBJECT.
Create Student->add Student to Student database (static ArrayList<Student> in my data layer)-> Add somehow Student from database to Map<Student, ArrayList<Integer>> grades in specific Lesson-so on this point it should (I dont know how) create ArrayList<Integer> in this map that is going to be connected with this specific Student.

GRADE STUDENT(SPECIFIC).
Find matching  Lesson object from ArrayList<Lesson> - > Find matching key-(for example: Student ID, but on our purpose its going to be just a surname) Student surname in grades Map- so they key would look like this Student.getSurname,equals/matches "Provided by user surname"-> Adding somehow records to Value part connected to specific Student-without overwriting past grades that he have got.
I got this theoretical but I have got no idea how to change it into practice.
 
Carey Brown
Saloon Keeper
Posts: 7393
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really have a database behind this or are you just referring to a data layer that behaves like a database?
Do you really need a Lesson class? The key for the Lesson class is lessonName so why not just use the name as a String instead of enclosing it in another Object?

Here's a simple way of doing this where the Student owns the storage for grades.

This is an educated guess. I don't have access to your original requirements.
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Do you really have a database behind this or are you just referring to a data layer that behaves like a database?
Do you really need a Lesson class? The key for the Lesson class is lessonName so why not just use the name as a String instead of enclosing it in another Object?

Here's a simple way of doing this where the Student owns the storage for grades.

This is an educated guess. I don't have access to your original requirements.



So maybe I will just input the architecture and what service my console app have.
ARCHITECTURE:


Admin logic:
Admin can create & delete:
Student account/Professor account.
Student logic:
Student can:
a)register to the specific Subject
b)check his grades from specific Subject
Professor logic:
Professor can:
a)create Subject
b)check Subject list
c)show list of Students registered to specific Subject
d)show average grades of all students from subject
e)show specific student grades from a subject
f)add grades from specific Subject to specific Student

Every (Subject/Professor/Student) object (excepted Admin) is created on application run and stored to static ArrayLists that pretending to be a database.

So in my opinion the only possible approach to finish this project is working with Subject/Lesson as an object-otherwise Professor methods wont work so yes, I think I need to make it with Map<Student(or Subject), ArrayList<String>> somehow
 
Carey Brown
Saloon Keeper
Posts: 7393
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your Repository have, or need to have, persistence behind it, such as files or database?
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Does your Repository have, or need to have, persistence behind it, such as files or database?



For now every Repository is just static ArrayList that stores objects created while the program is running(its provide me some kind of simulation of real program)  After I close the app-the Repository is cleared. After I will achieve all goals from logic(service) layer I will start developing real database-(mysql, hibernate will be included), later I will add interface and I will make it standalone application. Its for my self-learning purpose.

So I think I need Map that will  have as a key Object and accessing to add some value to it would be by Object.getSomehowANameInString ?
Something like:
"Map<Student, ArrayList<Integer>> gradesFromSpecificLesson"
but for adding value to specific Student, I would access to it by
lesson.put(Student.getName.matches(InputString), grades.add(InputInt)); ?
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So maybe I will just ask-in Your opinion is it possible to add all this functionality with leaving Lesson(Subject) as a String. not an object? If yes-I will try to figure it out somehow ;)
 
Campbell Ritchie
Marshal
Posts: 70684
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jan Kaczmarek wrote:. . . Map<Student, ArrayList<Integer>> . . .

Depends how the hashCode() and equals() methods work in Student. If a Student object can change its state and therefore its hash code, you will never find it in the Map again.
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Jan Kaczmarek wrote:. . . Map<Student, ArrayList<Integer>> . . .

Depends how the hashCode() and equals() methods work in Student. If a Student object can change its state and therefore its hash code, you will never find it in the Map again.


It can. So the answer anyway is Lesson as a String, not a Lesson object. I will try to implement it this way- and find way to make all this Student/Teacher funcionality on it-if its not going to work as I want it to do-I will just post it here for some hints. Thank you for all your support and patience!
 
Campbell Ritchie
Marshal
Posts: 70684
288
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somebody's sent me pie Thank you, JK
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Somebody's sent me pie Thank you, JK



This portion of patience from all of you for my ignorance deserve a pie The pleasure was all mine.
Anyway I think the solution for this problem may be Map with multiple key-cause String method cant provide me enough service possibilities. I will post my solution in this topic for posterity if I will figure out how to do it:P
 
Carey Brown
Saloon Keeper
Posts: 7393
66
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Lesson as a String is straight forward but may not be extendable in the way you need.
Using Lesson as an Object has some advantages in that you can add fields as needed but then you need to carefully consider how you implement equals() and hashCode().
As you progress towards persistence you may want a Lesson to have a lessonId, and use that in place of a Lesson reference or name.
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so I decided to go with solution
class Lesson
Map<Student, ArrayList<Integer>> grades.

Im trying to make method that will add to the Map<Student,ArrayList<Integer>> Student that have got specific pesel(ID number). Im trying to use stream but its just checking if in my static ArrayList<Student> (that is pretending to be database) is any object with same String and if yes-it returns true or false.

Im reading oracle documentation and I cannot find any good solution. Am I missing something or there is no answer right there and I should make some own method? I find it kinda weird because it seems to be simple, daily problem so it should provide some tools to make it works.
 
Jan Kaczmarek
Greenhorn
Posts: 14
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I decided to make method for this problem:

 

But I still think this is not correct way.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic