Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sab669
Sep 24, 2009

This is a pretty simple (I think) question, since I'm pretty retarded.

code:
    ArrayList<Dog> dList = new ArrayList<Dog>(numDogs);
    
    for (int i = 0; i < numDogs; i++)
    {
        Dog d1 = new Dog();        
        
        ....

        dList.add(d1);
    }
    
    Collection.sort(dList);

In the for loop I just have the user enter the the data for the Dog class.
The API says to use sort I need to implement the Comparable interface, which Dog does. But when I do that, I get an error saying

"Dog is not abstract and does override abstract method compareTo(java.lnag.Object) in java.lang.Comparable"

So yea, I'm trying to just alphabetize (and then display) an Array List. Not really sure what I'm doing wrong.

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

Why is equals() better than ==? I'm a huge noob at all of this... and in related news! The reason why I came to this thread.

I'm taking a Design Patterns course that uses Java, but I'm much more comfortable with the .net framework (specifically C#).

Trying to write a try-catch statement to verify some input from the user. Unlike a try-catch from what I'm used to, this REQUIRES some sort of error to throw- I can't just print out my own error message.

Basically

code:
try{
    difficulty = kb.nextInt();
} 
catch{
    System.out.println("Error: only enter 1-3");
}
I guess I'm not sure what the most "proper" way of doing this is?

e; Looks like I've just got to make my own class that interfaces* Exception?
*Is that the proper term? I can never keep abstract/interface/whatever else straight :(

Sab669 fucked around with this message at 00:45 on Oct 31, 2011

Sab669
Sep 24, 2009

Right right, thanks for the quick responses.

Sab669
Sep 24, 2009

I know there's a brief overview of a few IDEs on the first page, but I was hoping to get a little more information on Netbeans VS Eclipse.

I'm still a student, and when I took a Java course we used NetBeans. I'm taking a Design Patterns course this semester which is also in Java and the professor only lets us use Eclipse. So far, I'm not impressed with it at all- the intellisense seems slow as hell, unconventional hotkeys (at least, compared to what I'm used to) and just all around I don't feel comfortable in the environment.

Goons, why you do prefer one over the other?

Sab669
Sep 24, 2009

Can anyone recommend an easy-to-use UML-generating plugin for Eclipse? I really hate making the myself (or at least I just really hate Visio), but they're so helpful at times.

Sab669 fucked around with this message at 00:56 on Dec 1, 2011

Sab669
Sep 24, 2009

http://pastebin.com/cuTQJ4nU

I've got an error on lines 96 & 97, it tells me I should change the type of myCar to InteriorColor / ExteriorColor respectively.

But what I don't understand is Interior/ExteriorColor extend CarDecorator, which extend Car. This is for my design patterns class, doing a bonus assignment where we need to mix and match random patterns we've learned this semester, trying to use Decorator + Singleton patterns. But yea, no idea where my logic is wrong. As far as I can tell I've followed my previous homeworks exactly.

Sab669
Sep 24, 2009

I guess that's where I'm confused, because UniqueCar also extends Car, so isn't it technically a Car?

And in the two classes I've taken that use Java as the language, I've never heard of Synchronized.

Sab669
Sep 24, 2009

Am I creating an array of objects incorrectly, or something?

code:
public class Player{
	int age;
	String name;

	<<Setters and Getters generated by the IDE>>
}
code:
Scanner kb = new Scanner(System.in);		
Player[] players = new Player[10];		
		
	for(int i = 0; i < players.length; i++)
	{
		System.out.println("Enter your age: ");
		players[i].setAge(kb.nextInt());
			
		System.out.println("Enter your name: ");
		players[i].setName(kb.nextLine());
	}
Throws a NullPointerException on the setAge line.


edit; I figured out my problem! :downs:
I needed to add
code:
players[i] = new Player();
To the for loop

Sab669 fucked around with this message at 04:12 on Mar 8, 2012

Sab669
Sep 24, 2009

C# guy trying to help my roommate with Java; are variables not referred to as "fields" in a class in Java? He's a first-semester CS student and his vocabulary is pretty poor, which makes it difficult when I try to give him guidance on a lab.

Sab669
Sep 24, 2009

Any recommendations on some absolute bare-bones First Programming Language books for Java? My roommate is going into his second semester of Comp Sci and he's really struggling. Decided to wait until the last week of vacation to buy a book and try to get back into it before the next semester starts :v:

Java, A Beginner's Guide seems to have good reviews.

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

Gravity Pike posted:

Comp Sci II doesn't cover anything more complicated than, like, Generic Collections, right? It's been forever.


His first semester class was actually pretty weird. They covered basic data types, then jumped into objects and interfaces then flow control and loops. They did a bit with ArrayLists as well, never having even talked about just basic arrays.

By the end of the semester he barely comprehended the concept of 'returning' a value from a method, constructors, or creation of variables for things other than basic data types. I don't know if his professor sucked, or it was a lack of sufficient labs to give him practice or what.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply