Carey Brown wrote:
Iwan van den Hoek wrote:In Student administration I have 2 Arraylists one for students and one for Study's and courses. A student can be a RegulierStudent with a study or a scholer with a course, but not both.
I have to add a student based on the textfield in the Gui to the studenten ArrayList and check the already filled opleidingen Arraylist for the Study based on the selected String value in the pulldown menu from the Jcombobox.
if the chosen String value corresponds with a Value in the opleidingen ArrayList I want to add the student with that particular study/course to the studenten Arraylist.
In pseudo code (is this correct?)
Knute Snortum wrote:In the opleiding combo box you're putting:
But in the opleidingen you're putting:
This is the problem with using Strings the way you are. You should be using an enum.
There are three kinds of actuaries: those who can count, and those who can't.
Liutauras Vilda wrote:No no, wait. That is the problem. You're telling how you need to do it without knowing what you need to do. Don't use any Java terms, we're not interested in those - we know some ourselves.
Don't tell anything about the GUI, problem most likely is not there. Don't even use your variable names in explanation, these could be not accurately chosen and they are in other language.
Not sure understood that. Is regular student the one who enrolled to a full study programme, and the other type is the one who only enrolled to a one particular module to study?Iwan van den Hoek wrote:A student can be a RegulierStudent with a study or a scholer with a course, but not both.
Elaborate and expand more the quote below, this one is the way closer to what we want to hear from you.
Iwan van den Hoek wrote:... I want to create a new Student with the selected study...
Before you tell us in non technical language what is the exact task, please read tutorials StopCoding and WhatNotHow.
Note: The way you tried to solve this exercise, gave you the result you have now, if you're going to continue solving that way, the result going to be the same. So read those tutorials, and describe the task in plain english (in details, but without technical terminology).
There are three kinds of actuaries: those who can count, and those who can't.
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.
Carey Brown wrote:From Google Translate:
Here is the assingment:
.
Carey Brown wrote:Please don't quote huge blocks of text if you can help it.
Carey Brown wrote:Out of curiosity, what does CPP mean/stand for ?
There are three kinds of actuaries: those who can count, and those who can't.
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).
There are three kinds of actuaries: those who can count, and those who can't.
All things are lawful, but not all things are profitable.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:I would loop through opleidingen and add each item with a opleidingen.get(index).
There are three kinds of actuaries: those who can count, and those who can't.
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.
There are three kinds of actuaries: those who can count, and those who can't.
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.
All things are lawful, but not all things are profitable.
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):
All things are lawful, but not all things are profitable.
Knute Snortum wrote:What exactly are you stuck on now?
All things are lawful, but not all things are profitable.
Knute Snortum wrote:How about passing in your combo box and using:
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.
All things are lawful, but not all things are profitable.
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.
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|