Two Plus Two Publishing LLC
Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 11-21-2018, 08:19 PM   #1976
matrat
adept
 
matrat's Avatar
 
Join Date: Jan 2011
Location: fasting
Posts: 900
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Chips Ahoy View Post
I see. How about if you filter operations which add products. Make an add method for each type you accept. Then treat everything as a product after that.
Ya I suppose I could do something like this. It's not very explicit on how it's to be done. Thanks everyone.
matrat is offline   Reply With Quote
Old 11-22-2018, 08:46 PM   #1977
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 40,283
Re: Programming homework and newbie help thread

That's a horribly written assignment. It's not clear whether you're supposed to write your own Collection, or just wrap one like you've done. Have you covered implementing interfaces yet?

Then there's no good way to subclass GenericOrder in the way that it wants you to do. I guess I'd do what Chips suggested, have a guard clause on your add method which throws an exception if you try to add Products of the wrong types. By the way, "takes an arbitrary number of different classes" flat out does not make sense, I guess he means "objects" not "classes".

One thing that is clear is that you are supposed to write a generic class:

Quote:
Design a generic container called GenericOrder that acts as a collection of an arbitrary number of objects in Products.java. Design a mechanism that gives each instance of the container a unique identifier. Implement as many methods as necessary. You must use Java generics features.
So your class signature is going to need to be:

Quote:
public class GenericOrder<T> {
And I guess you want to wrap a List<T> or something. It's a dumb assignment because you're "designing a collection" that actually just wraps an already existing collection. But I can't believe that he wants you to implement Collection<T> from scratch, that seems too difficult for where you're at.

After that, subclass GenericOrder to ComputerOrder, override any method which adds to the collection, and throw an IllegalArgumentException if the object(s) aren't instances of one of the allowed classes, then call super.whateverMethod().

Last edited by ChrisV; 11-22-2018 at 08:55 PM.
ChrisV is offline   Reply With Quote
Old 11-23-2018, 08:46 PM   #1978
matrat
adept
 
matrat's Avatar
 
Join Date: Jan 2011
Location: fasting
Posts: 900
Re: Programming homework and newbie help thread

Ya overall I really dislike the class. It's offered at an online university and I'm taking it as a transfer credit so I don't need to take the B&M version at my school. The entire instruction is just getting assigned dozens of pages to read from the textbook for each unit with no additional video lectures or notes/slides to go over the most important sections. Lots of stuff in the textbook readings is just entirely not necessary for the course and is just too much to absorb. The first assignment I did I also thought had poorly written instructions, but as a saving grace the grading doesn't seem to be overly strict.

Anyways, ya there's no way I'm supposed to design a collection from scratch like you were possibly saying, it's just really poorly worded. This is an intro to Java course for people who only have a couple of comp sci classes under their belt, and this is the second assignment.

As for doing this: public class GenericOrder<T> {, I see that everywhere online when looking this stuff up, but the textbook only have examples similar to what I've done below with using <Product>. What I have so far is compiling at least, not sure if it actually works yet tho. Still need to add the illegal argument exception.

matrat is offline   Reply With Quote
Old 11-24-2018, 03:52 AM   #1979
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 40,283
Re: Programming homework and newbie help thread

I mean the assignment definitely states that the class you write is supposed to be generic, which yours isn't, but with how poorly the rest of the assignment is worded, who knows. There's actually no point making it a generic class, because you're always using it for Products, so you could easily be correct that writing a generic class is not intended. I'd check with your tutor if possible.

Couple other comments:

Your method for making a unique identifier is no good, most obviously because it resets to 1 any time the program restarts. Using static variables for global state is generally frowned on(*), it has other, more technical issues. For example it will cause problems if an application ever has to be load-shared across more than one server (when each server will have its own copy of the static variable) and it can cause thread-safety issues. The usual way of producing unique identifiers from nowhere is to use GUIDs, or java.util.UUID in Java. New one up in the constructor.

Secondly, the way you've subclassed ComputerOrder is insufficient, because I can still do this:

Quote:
ComputerOrder order = new ComputerOrder();
Cheese deliciousCheese = new Cheese();
order.add(deliciousCheese);
The general version of add() is still available from the superclass. Rather than creating new methods for each subtype allowed in ComputerOrder, override the original add method and throw an IllegalArgumentException if the Product is not of an allowed type. That's not how we'd normally do something like that, by the way, because it's setting traps for users of the class, but it's forced on us by the assignment.

* If you're wondering "well what the hell do I use for global state, if I don't use static variables?" then the answer is: 1. Avoid having global state whenever possible and 2. if it's unavoidable, use a singleton. This is in a footnote because it's advanced and not very relevant, just thought I'd put it in in case you were wondering.
ChrisV is offline   Reply With Quote
Old 11-24-2018, 04:01 AM   #1980
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 40,283
Re: Programming homework and newbie help thread

Just a bizarre assignment though, like the assignment is to create a subclass, but instead of being a nice neat demonstration of polymorphism, you have to do explicit type-checking in the method and throw exceptions if someone tries to do something naughty with a ComputerOrder. It's not at all a good demonstration of OO programming.
ChrisV is offline   Reply With Quote
Old 11-24-2018, 10:20 AM   #1981
matrat
adept
 
matrat's Avatar
 
Join Date: Jan 2011
Location: fasting
Posts: 900
Re: Programming homework and newbie help thread

Ok I have this now and it works.

matrat is offline   Reply With Quote
Old 11-24-2018, 08:03 PM   #1982
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 40,283
Re: Programming homework and newbie help thread

Yup looks good. Going to be amused if the teacher tells you you weren't supposed to do it that way.

Couple pieces of pedantic nittery: It's considered good practice to annotate overridden methods with @Override, see When do you use Java's @Override annotation and why? Also, standard is to use "public void addProduct...". Java's default access level is for stuff to only be accessible within the same package. Use public whenever you have no reason to want to restrict access. It doesn't actually matter here but it's just similar to nit stuff in English like capitalizing words properly, makes you look like you know what you're doing.

Edit: While I'm nitting it up, since you're learning OO, slightly better than productArray.add(product) is super.add(product). That way GenericOrder's implementation of add() could be changed in the future and the ComputerOrder class doesn't have to know or care.

Last edited by ChrisV; 11-24-2018 at 08:21 PM.
ChrisV is offline   Reply With Quote
Old 11-24-2018, 11:45 PM   #1983
matrat
adept
 
matrat's Avatar
 
Join Date: Jan 2011
Location: fasting
Posts: 900
Re: Programming homework and newbie help thread

I'll change that stuff, thanks for the tips.

I miss using python for everything :'(
matrat is offline   Reply With Quote
Old 05-11-2019, 11:27 AM   #1984
de4df1sh
Carpal \'Tunnel
 
de4df1sh's Avatar
 
Join Date: Feb 2014
Location: mobtown
Posts: 6,009
Re: Programming homework and newbie help thread

Hi guys, im a bit stuck on this project. I can answer 1 and 3 but im a little stumped by 2. I think the answer could be either group age or name, but am unsure how to arrive at the proper conclusion

CRAP, how do I insert pictures from my local machine in here?
de4df1sh is offline   Reply With Quote
Old 05-11-2019, 12:15 PM   #1985
de4df1sh
Carpal \'Tunnel
 
de4df1sh's Avatar
 
Join Date: Feb 2014
Location: mobtown
Posts: 6,009
Re: Programming homework and newbie help thread

de4df1sh is offline   Reply With Quote
Old 05-11-2019, 12:15 PM   #1986
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,948
Re: Programming homework and newbie help thread

Quote:
Originally Posted by de4df1sh View Post
CRAP, how do I insert pictures from my local machine in here?
Upload them to an online image host, such as https://imgur.com, then copypaste their provided bbcode in your post here (or use the direct link in an image tag if you can).

edit: I see you got it
_dave_ is online now   Reply With Quote
Old 05-11-2019, 12:16 PM   #1987
de4df1sh
Carpal \'Tunnel
 
de4df1sh's Avatar
 
Join Date: Feb 2014
Location: mobtown
Posts: 6,009
Re: Programming homework and newbie help thread

Quote:
Originally Posted by _dave_ View Post
Upload them to an online image host, such as https://imgur.com, then copypaste their provided bbcode in your post here (or use the direct link in an image tag if you can).

edit: I see you got it
Hah we were seconds apart!
de4df1sh is offline   Reply With Quote
Old 05-11-2019, 12:37 PM   #1988
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,948
Re: Programming homework and newbie help thread

I think it has to be "name".
_dave_ is online now   Reply With Quote
Old 05-11-2019, 12:38 PM   #1989
de4df1sh
Carpal \'Tunnel
 
de4df1sh's Avatar
 
Join Date: Feb 2014
Location: mobtown
Posts: 6,009
Re: Programming homework and newbie help thread

So I think that the name would be the primary key because the group is dependant on that. Is that right?
de4df1sh is offline   Reply With Quote
Old 05-11-2019, 12:39 PM   #1990
de4df1sh
Carpal \'Tunnel
 
de4df1sh's Avatar
 
Join Date: Feb 2014
Location: mobtown
Posts: 6,009
Re: Programming homework and newbie help thread

Quote:
Originally Posted by _dave_ View Post
I think it has to be "name".
hah we did it again
de4df1sh is offline   Reply With Quote
Old 05-11-2019, 12:46 PM   #1991
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,948
Re: Programming homework and newbie help thread

Yes, for each name the group is distinct - which makes sense, "Susan" is only "6 years old" in any row, and there can not be more than one "Susan" according to the instructions. You can't use "age group" as a primary key since it has multiple records associated with it - 6 has Susan and Carrie.

What are your answers to 1 and 3?
_dave_ is online now   Reply With Quote
Old 05-11-2019, 12:52 PM   #1992
de4df1sh
Carpal \'Tunnel
 
de4df1sh's Avatar
 
Join Date: Feb 2014
Location: mobtown
Posts: 6,009
Re: Programming homework and newbie help thread

Quote:
Originally Posted by _dave_ View Post
Yes, for each name the group is distinct - which makes sense, "Susan" is only "6 years old" in any row, and there can not be more than one "Susan" according to the instructions. You can't use "age group" as a primary key since it has multiple records associated with it - 6 has Susan and Carrie.

What are your answers to 1 and 3?
I'll condense it down as I have a tendency to fluff things out for appearence purposes.

1. This is at least 1NF because all of the values are atomic, our columns are unique. Even though we have some repeating values this still qualifies.

3. The problem here is that Jaqueline shares value with others such as age and group. We cannot trace the visual basic game back because it could be either susan or charlotte
de4df1sh is offline   Reply With Quote
Old 05-11-2019, 01:13 PM   #1993
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,948
Re: Programming homework and newbie help thread

Actually, I think it probably wants you to use a composite primary key of (name, game). This pairing is unique.
_dave_ is online now   Reply With Quote
Old 05-11-2019, 09:53 PM   #1994
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 40,283
Re: Programming homework and newbie help thread

Quote:
Originally Posted by de4df1sh View Post
I'll condense it down as I have a tendency to fluff things out for appearence purposes.

1. This is at least 1NF because all of the values are atomic, our columns are unique. Even though we have some repeating values this still qualifies.
That's correct.

2. This is a poor question, but the answer is { GIRL, GAME } as that's the smallest number of columns which is unique for each row. The reason it sucks as a question is that "assume the tuples shown are the only possible tuples for all time" is an unrealistic assumption and not how you'd normally go about choosing a key. This choice of key will fall apart if a product gets introduced in the Games category which is called "Mirror", for example, then the key would need to be { GIRL, GAME, CATEGORY }. In a properly normalized database { GAME, CATEGORY } would be off in a sub-table anyway.

Quote:
Originally Posted by de4df1sh View Post
3. The problem here is that Jaqueline shares value with others such as age and group. We cannot trace the visual basic game back because it could be either susan or charlotte
I'm not sure what you're trying to say here. Here's a definition for "deletion anomaly":

Quote:
Occurs when a record is deleted and this results in the loss of other data that only occurs in that record.
Defining "other data" here is a bit tricky because it's not entirely clear to me what this table even represents. Is it a record of sale? Let's assume it is. In that case the loss of "Jacqueline", "Visual Basic" and "Prog. Languages" are all deletion anomalies. The aim of deleting that tuple is to remove the record of sale, but a side-effect is that we lose the information of the existence of the three things above. The price is also unique information lost, but it's not a deletion anomaly because my understanding is that's the data we're intending to delete.

You're not wrong to be confused by those questions, they're not well constructed.

Last edited by ChrisV; 05-11-2019 at 10:09 PM.
ChrisV is offline   Reply With Quote
Old 05-12-2019, 02:54 AM   #1995
de4df1sh
Carpal \'Tunnel
 
de4df1sh's Avatar
 
Join Date: Feb 2014
Location: mobtown
Posts: 6,009
Re: Programming homework and newbie help thread

Quote:
Originally Posted by ChrisV View Post
That's correct.

2. This is a poor question, but the answer is { GIRL, GAME } as that's the smallest number of columns which is unique for each row. The reason it sucks as a question is that "assume the tuples shown are the only possible tuples for all time" is an unrealistic assumption and not how you'd normally go about choosing a key. This choice of key will fall apart if a product gets introduced in the Games category which is called "Mirror", for example, then the key would need to be { GIRL, GAME, CATEGORY }. In a properly normalized database { GAME, CATEGORY } would be off in a sub-table anyway.



I'm not sure what you're trying to say here. Here's a definition for "deletion anomaly":



Defining "other data" here is a bit tricky because it's not entirely clear to me what this table even represents. Is it a record of sale? Let's assume it is. In that case the loss of "Jacqueline", "Visual Basic" and "Prog. Languages" are all deletion anomalies. The aim of deleting that tuple is to remove the record of sale, but a side-effect is that we lose the information of the existence of the three things above. The price is also unique information lost, but it's not a deletion anomaly because my understanding is that's the data we're intending to delete.

You're not wrong to be confused by those questions, they're not well constructed.
Thanks, Chris I appreciate your input. Fortunately, I have until Sunday 12a to submit the answers. Since I'm transferring out I'm happy to bring up any and all critical feedback.
de4df1sh is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 10:26 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online