Iwan van den Hoek

Ranch Hand
+ Follow
since Jan 29, 2015
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Iwan van den Hoek

Knute Snortum wrote:

Or should i use a arraylist getter and create a variable in the frame based on the getter and then use the for loop in the frame.


If I'm understanding you, this sounds correct. Assuming that StudentenAdministratie can be instantiated in StudentAdminFrame. You need to be able to access opleidingen from the StudentAdminFrame class, something like:

Notes: this is not a good design, but I get the feeling you just want to get this assignment over with. At some point you should come back to this a design it better. We can talk about that later if you want.

Also, I don't have your latest code, or the complete code, as there is no main() in any class and I don't think you are using a framework.



Hi Knute,

Yes this is true as well, I needed it to be finished. The new assignment is to make the application robust and start working with Throw Exception.

I have solved it with the code below:


Thank you for your help and everyone else as well.

So I will speak to you guys soon enough with the new assignment :-) and Knute I would definately want to learn how to do this in a better way.
9 years ago

Knute Snortum wrote:How about passing in your combo box and using:



Hi knute

Could you elaborate on that. As the method is in the studentenadminitratie class and not in the GUI frame class where the combobox is.

Or should i use a arraylist getter and create a variable in the frame based on the getter and then use the for loop in the frame.



9 years ago

Knute Snortum wrote:What exactly are you stuck on now?



Getting the values in the combobox with a method.
The method I have tested are as follows:

But this only returns the object reference, I added a toString from Studie but that doesn't help, probably not strong enough (don't really know what that means)

I have tried the one in the previous post and as Piet explained that will only show the last value.

So I need a way to get the values in the 2 combobox
9 years ago

Knute Snortum wrote:I believe you need to either add the items to your combo box one by one...

...or add them all when you create the combo box:

(The method name "getOpleidingen" is not a good one; I'd call it something like "convertOpleidingenToArray".)

But it would be even better if you could add the Opleidingen objects themselves. (Opleidingen would need a good toString() method):



Unfortnately that won't work as I can't access any other class then StudentenAdministratie from the Frame class. We need to use inheritance.

I need a method in StudentenAdministratie that checks the Arraylist<Studie> for the values
With a cast to CPP and Opleidingen because I have two comboboxes one that only fills the Opleidingen (studies) and one that fills the CPP(courses)

The ArrayList has both the Opleidingen and CPP's stored in there and with instanceof I can differentiate them.

If I could access all teh classes from the GUI it would be a lot easier, but the assignment doesn't allow it.

that is why I am stuck :-(
9 years ago

Piet Souris wrote:I see...

Well, have a look at your latest method. You have this line in your loop:

and when the loop is over, you return this 'test'. No wonder you only see the last one!

I suggest you change this method into something like:

Edit: oops, I should have read a little better. What exactly are your needs? Do you have one combined List<Studie> and do you need to get that plitted into a List<Opleiding> and a List<CPP>? If so, then 'instanceof' works well.
Creating a JComboBox is then also easy, just add (in a loop), all the elements of one of these Lists into your box. unfortunately, a JComboBox only has constructors that take either an array or a Vector.

Hope I'm a bit clearer, now.



Hi Piet,

Yes I have one combined ArrayList<Studie> and have to get a List <Opleiding> and a List<CPP>.
Should I use the instanceof in the method as shown above?
9 years ago

Piet Souris wrote:hi Iwan,

Regarding your question about these comboboxes:
an easy way to get these boxes filled without looping is something like:

List<Opleiding> opleidingen = ...;
...
JComboBox<Opleiding> comboOpleiding = new JComboBox<>(opleidingen.stream().toArray(Opleiding[]::new));
// or new JComboBox<>(new Vector<>(opleidingen));

You need a decent toString() method though.
If you ever change one of those Studie-lists, then there are nice ways to inform the comboboxes of these changes. But that for later.


Hi Piet,

Thank you for the example, the only thing is that it will not work for this assignment.
The Gui can only access the StudentAdministratie class and the Studie class is associated with StudentenAdministratie.
Studie class has 2 subclasses Opleiding and CPP.

The Array List Studie is filled with opleidingen en cpp's.

So I need to get the values from this Arraylist and populate them in the Jcombox. Also I need to get the opleidingen in the Student combobox and the cpp's in the Scholer combobox.

That's why I thought that use a for loop in the arraylist would be my best shot, but it is only returning the last value :-(

So if you could help me with this that would be great.

9 years ago
Hi Knute,

I have created a method in StudentAdministratie class that gets all the String values.


But when I call the method from the combobox it only shows the last value.

How can I get it to show all the values in the combobox?
9 years ago

Knute Snortum wrote:I would loop through opleidingen and add each item with a opleidingen.get(index).



Hi Knute,

Thank you, I am trying to do that, but kinda stuck on how to do that.
The ArryList is from class Studie and is created in StudentAdministratie class.

StudentAdminFrame can only access Studentadministratie class

So I need to get the value with a getter in StudentAdministratie class.

It's probably not that difficult but somehow I am not getting it done :-(
9 years ago
I want to thank everyone for their help.
i have managed to get the program to work properly.

the only thing now is that the teacher is not happy with how I populate the Jcombox.
This is how I do it, but the string value should not be hardcoded. He said that I need to get the info from the ArrayList opleidingen



I have tried it with a getter but I don't get the value back

Any Idea's on how to to it?
9 years ago
Hi everyone,

At this point I have managed to get it working (not as good as I want),.
The Null pointer I got came from an incomplete constructor in study.

I will keep posting some of the progress and I Still have to make it robust.

@knute

Your example on enum does look good, I want to try it, but we need to make the application with a Study class with 2 subclasses opleiding and cpp.
I will try to see if I can still use the enum in that matter. if you have a tip on how let me know


9 years ago

Piet Souris wrote:hi Iwan,

Well, the assignment is there, and I hope that Google's work is good enough for those poor ones who do not speak Dutch! Important is that it is about inheritance and dynamic binding.

A question: now that your NPE is solved, are you satisfied with what you have so far? Does it fullfill the assignment? And that is apart from the GUI, just the classes and the interfaces concerning the Studies and the Students (and the administration, of course).



Hi Piet,

Unfortnately I am stumbeling on a new Nullpointer exception, when I want to ask for name of the study for the student.
student.getStudie().getNaamStudie() is causing the Nullpointer

9 years ago

Carey Brown wrote:Out of curiosity, what does CPP mean/stand for ?


Hi Carey

It means certified professional program.
9 years ago

Carey Brown wrote:Please don't quote huge blocks of text if you can help it.


You are absolutly right. Didn't think it through. I have edited the post.
9 years ago

Carey Brown wrote:From Google Translate:

Here is the assingment:

.



Thank you Carey,

I posted the Dutch one for Piet.
9 years ago

Piet Souris wrote:hi Iwan,

indeed I am from Holland. Can you put that assignment here in this topic? We can translate all that's necessary, if someone asks for it.



Here is the assingment:
Een eenvoudige studentenadministratie
In deze opgave maken we een applicatie die gebruik maakt van zelf
ontworpen klassen waarbij overerving en dynamische binding centraal
staan.
Een studentenadministratie beheert studenten. Een student kan een
reguliere student of een deelnemer aan een scholingstraject (scholer) zijn.
Van een reguliere student wordt de opleiding vastgelegd waarbij deze is
ingeschreven, van een scholer het CPP. We gaan ervan uit dat reguliere
studenten en scholers gescheiden groepen zijn, dat wil zeggen een
scholer is geen reguliere student en een reguliere student is geen scholer.
Er zijn twee opleidingen, namelijk Informatica en Wiskunde.
Er zijn drie CPP’s, namelijk CPP Java, CPP Softwarearchitect en CPP
Systeemontwikkelaar.
We maken een applicatie voor het invoeren en tonen van studenten met
de volgende mogelijkheden en randvoorwaarden:
– Van alle studenten wordt de naam ingevoerd en vastgelegd.
– Van reguliere studenten worden de opleiding waarbij ze staan
ingeschreven en het aantal behaalde studiepunten vastgelegd. Hoewel de
volledige opleiding uit een geheel aantal studiepunten bestaat, kan er per
keer ook een gebroken aantal punten behaald worden (bij de OU zijn er
vakken van bijvoorbeeld 4.3 studiepunten). Het aantal behaalde
studiepunten is dus een gebroken getal.
– Van scholers wordt het CPP en het aantal behaalde modules
vastgelegd. Dit laatste is een geheel getal.
– Van iedere opleiding wordt de naam en het totaal aantal studiepunten
vastgelegd: Wiskunde 160, Informatica 200. Dit totaal is altijd een geheel
getal.
– Van ieder CPP wordt de naam en het aantal modules waaruit het CPP
bestaat vastgelegd. (Het CPP Java bestaat uit 6 modules, het CPP
Softwarearchitect uit 4 en het CPP Systeemontwikkelaar uit 3)
– Het systeem moet de mogelijkheid hebben de gegevens van alle
studenten te tonen: naam, opleiding of CPP, aantal behaalde modules of
studiepunten en of de student geslaagd is.
Aanwijzingen
Het gaat in deze opdracht om een goed gebruik van overerving en
dynamische binding. De applicatie hoeft niet robuust te zijn; er hoeft
bijvoorbeeld niet na te gaan of invoervelden leeg zijn, en of
studentnamen uniek zijn, etc.
Als bouwsteen krijgt je een klasse StudentAdminFrame die de grafische
interface voor de studentadministratie vormt. De volgende figuren tonen
de verschillende delen van de user interface en nog enkele extra
aanwijzingen voor de gewenste functionaliteit.

Nieuwe student
Tabblad nieuwe student dient om een nieuwe reguliere student te
kunnen invoeren. Om het niet te ingewikkeld te maken, worden alleen
achternamen ingevoerd.
Na klikken op de knop Voeg student toe wordt in dit geval een nieuwe
student Jansen met opleiding Informatica toegevoegd aan de studenten.
De combobox bevat alle reguliere opleidingen waaruit gekozen kan
worden.
In deze niet‐robuuste versie hoeft niet gecontroleerd of de student al
bestaat en mag dus een eerder toegevoegde student of scholer
overschreven worden.

2 Nieuwe scholer
Het tweede tabblad dient om een nieuwe scholer in te voeren.

De functionaliteit is gelijk aan die van nieuwe student maar nu wordt een
scholer met zijn bijbehorende CPP‐opleiding toegevoegd aan de
studenten.

3 Studentinfo
Op het derde tabblad wordt informatie over een student getoond en kan
worden aangegeven dat deze een onderdeel van de studie heeft behaald.
Als de naam van een student ingevoerd is en op enter is gedrukt,
verschijnt de informatie van de student onderin het scherm. Deze
informatie bestaat uit de naam, de naam van de opleiding of van het
CPP, de behaalde studiepunten of het aantal behaalde modules en of een
student al dan niet geslaagd is.
Ook kan met dit scherm het aantal studiepunten (door aantal punten op
te geven in tekstveld, gevolgd door enter) of het aantal modules (door op
knop te drukken wordt het aantal modules met één verhoogd) van de
student worden verhoogd. Wanneer dat wordt gedaan, dan moet ook
weer de meest actuele informatie van de student worden getoond.
Hierbij mag de operatie alleen slagen wanneer deze bij het type student
hoort (in deze niet‐robuuste versie mag een verkeerde operatie eventueel
wel tot een exception leiden).

Alle studenten
Het vierde tabblad toont, bij een druk op de knop, de gegevens van alle
studenten. Voor iedere student wordt dezelfde informatie getoond als op
het vorige tabblad: naam, de naam van de opleiding of van het CPP, de
behaalde studiepunten of het aantal behaalde modules en of een student
al dan niet geslaagd is.
9 years ago