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
Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.
Well, it seems that you've implemented a For-Switch, which is a common enough mistake that it's got its own wikipedia page. It's a good way to exercise both of those control structures, but you generally want to choose whether you're doing something sequentially or in a loop. ("Both" is the wrong answer.)

In Comptuer Science we count starting at 0. In Java, we name classes starting with a capitol letter, in CamelCase, using full words. I can't see where you're using keybd to gather input at any point in time... unless it's in the Cat class? It's good practice to have "setter methods" accept an argument, rather than gather their own data. This way, you can load values from a database, or a text file, or by randomly generating them, and still use the same Cat class and setters.

I implemented a simple solution before I re-read your line that says you don't use Arrays yet. (That is crazy. Using arrays makes this simpler.) Arrays (or their big-brothers, Collections) are the correct way to manage storage of many of the same type of thing.

Java code:
public class CatDriver {
	public static void main(String[] args) {
		Scanner keybd = new Scanner(System.in);
    Cat[] cats = new Cat[3];

    for (int i = 0, i < 3, i++)
    {
      System.out.println("Enter the name of Cat " + i + ": ");
      String name = keybd.nextLine();
      System.out.println("Enter the age of Cat " + i + ": ");
      int age = keybd.nextInt();
      System.out.println("Enter the weight of Cat " + i + ": ");
      double weight = keybd.nextDouble();
      System.out.println("Enter the breed of Cat " + i + ": ");
      String breed = keybd.nextLine();
      System.out.println("Does the cat have claws? True or False?");
      boolean claws = keybd.nextBoolean();
      
      Cat myCat = new Cat();
      myCat.setName(name);
      myCat.setAge(age);
      myCat.setWeight(weight);
      myCat.setBreed(breed);
      myCat.setClawed(claws);
      
      cats[i] = myCat;
    }
  }
}
I guess you could use a switch to create a ghetto-array:

Java code:
  Cat cat0 = new Cat();
  Cat cat1 = new Cat();
  Cat cat2 = new Cat();
  
  for (int i = 0; i < 3; i++) {
    Cat currentCat;
    switch (i) {
      case 0:
        currentCat = cat0;
        break;
      case 1:
        currentCat = cat1;
        break;
      case 2:
        currentCat = cat2;
        break;
      default:
        throw new RuntimeException("THERE ARE TOO MANY CATS!");
        
    }
    
    currentCat.setName(name);
    //etc
    
  }
... but this is Too Much Work in order to achieve the same result. If you can't use arrays, could you use a function?

Java code:
public class CatDriver {
	public static void main(String[] args) {
		Scanner keybd = new Scanner(System.in);
    Cat cat0 = buildCat(keybd, 0);
    Cat cat1 = buildCat(keybd, 1);
    Cat cat2 = buildCat(keybd, 2);

  }
  
  private Cat buildCat(Scanner scanner, int catNum) {
    System.out.println("Enter the name of Cat " + catNum + ": ");
    String name = scanner.nextLine();
    System.out.println("Enter the age of Cat " + catNum + ": ");
    int age = scanner.nextInt();
    System.out.println("Enter the weight of Cat " + catNum + ": ");
    double weight = scanner.nextDouble();
    System.out.println("Enter the breed of Cat " + catNum + ": ");
    String breed = scanner.nextLine();
    System.out.println("Does Cat " + catNum + " have claws? True or False?");
    boolean claws = scanner.nextBoolean();
    
    Cat myCat = new Cat();
    myCat.setName(name);
    myCat.setAge(age);
    myCat.setWeight(weight);
    myCat.setBreed(breed);
    myCat.setClawed(claws);
      
    return myCat;
  }
}

Gravity Pike fucked around with this message at 08:16 on Dec 10, 2013

Adbot
ADBOT LOVES YOU

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Bullio posted:

I'm very new to coding, I hope I'm not wasting your time with such a low level question, but goons never let me down before.

Don't worry, we like the easy questions. They're easy to answer, and make us feel superior. :smuggo:

Bullio posted:

For class, I'm doing a simple little program where a user inputs information for 3 cats and the program outputs which cats listed are over 3 years and declawed. I finished it already and turned it in, but I'm looking for advice on a more elegant way to do it as opposed to the clutter I made grinding it out when I turned it in. We don't hit arrays until next semester and I couldn't figure out how to set up just one block of questions and apply the data to the correct object instance. So I made a set of System.out.println for each cat, which is ugly as hell. Anyway, using a for loop with a switch statement is the way to go, I think, but I keep getting problems in the implementation. Sorry if this is too low level.

Also, will this print out properly? i.e. "Enter the name of Cat 1:" "Enter the name of Cat 2:" etc

Sounds like you could organize some of this logic as a seperate method/function to call, which is something newbie programmers are usually very hesitant to do, but becoming comfortable with it is the real way to Getting It™ as a programmer. Rather than knock everything out in one method, build yourself some tools first, and then you can use those tools in a much simpler method.

That'll print out properly as you're expecting, however it'll print all of the "Enter:" blocks at once, and then go to your section which I guess would read the inputs? You may want to prompt separately for each one as you take the inputs.


Hah, I didn't know it had a wiki page, that's funny.

Gravity Pike posted:

In Comptuer Science we count starting at 0. In Java, we name classes starting with a capitol letter, in CamelCase, using full words.

Thing is he didn't make an off-by-1 error, so its not a big deal. So he's wasting a bit, in modern performance when you're learning that's trivial. I guess its good to know that you can count from zero, but really, that's minor. Making the off-by-one error is the real mistake, and he avoided that. It also prevents him from having to do i+1 on each loop iteration... so that's actually more efficient.

You should def get comfortable with camel case though, its a really good habit to get into.

variables and methods begin lower, then go capital. Classes begin capital. That way you can tell at a glance if something is a class or a feature of a class, and the capitols after the first make it much easier to read (since you aren't allowed spaces)

thisisreallyhardtoread

ThisIsPrettyEasyToRead

ClassName

methodName

variableName

Zaphod42 fucked around with this message at 23:52 on Dec 10, 2013

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
I think the big problem is finding a format that would be "acceptable" for his class. If he's not allowed to use arrays, he's probably not allowed to make methods aside from main, not allowed to use OO, etc. There's only so much you can do when you're limited in this way.

Bullio
May 11, 2004

Seriously...

Wow. I appreciate the great responses. To tell you the truth, I was nervous about even posting with all the pros around here. I'm really grateful. Anyway, it was late when I was trying to write that up, so I didn't realize that I left no room for user inputs. It was all cobbled together pretty badly.

Volmaria is right, it's finding something using only the tools we've learned so far that's making it difficult. Seeing all these awesome efficient ways to get a job done makes me jealous of people with a more comprehensive knowledge.

Zaphod, in the for loop, I put i=1 instead of i=0 because I wanted it to name the objects myCat1, myCat2, etc. I'm thinking I'm wrong in how it'd do the naming conventions. I got Joyce Farrell's Programming Logic and Design Comprehensive on the recommendation from my instructor when I asked him what additional books I could read to help get acquainted with programming in general. I learned about camel case in that, but I'm still trying to develop the habit.

Gravity Pike, fields and arrays are still beyond me. To tell the truth, I only knew about arrays because I skipped ahead in the book and tried to shoehorn one in for a password verification program. It didn't go well because I didn't select the right type or something. We won't get into those until CS219 though.

To give you a better idea of what I'm going for, I'll post the assignment I did turn in that's slapdash, but meets the program requirements. Thing is, I don't want to be bad at this. I'd rather gain the skills and knowledge necessary to write elegant code that's easy to read and modify. I got Joyce Farrell's Programming Logic and Design Comprehensive on the recommendation from my instructor when I asked him what additional books I could read to help get acquainted with programming in general.

Here's what I turned in. You experienced types might want to brace yourself, it's ugly and inefficient. I will say that I love this whole object oriented programming. Having the method calls in another file makes it way easier to troubleshoot.


[b]Cat class
code:
public class Cat
{

	private String breed;
	private boolean declawed;
	private String name;
	private int age;// in years
	private double weight;// in pounds

	public String getName()
	{
		return this.name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public int getAge()
	{
		return this.age;
	}

	public void setAge(int age)
	{
		this.age = age;
	}

	public double getWeight()
	{
		return this.weight;
	}

	public void setWeight(double weight)
	{
		this.weight = weight;
	}

	public String getBreed()
	{
		return this.breed;
	}

	public void setBreed(String breed)
	{
		this.breed = breed; // age and weight are unchanged.
	}

	public boolean getDeclawed()
	{
		return this.declawed;
	}

	public void set(boolean declawed)
	{
		this.declawed = declawed;
	}

	public void set(String name, int age, double weight, String breed, boolean declawed)
	{
		this.name = name;
		this.age = age;
		this.weight = weight;
		this.breed = breed;
		this.declawed = declawed;
	}

	public void display()
	{
		System.out.println("Cats over the age of 3 that aren't declawed are"
				+ getName());
	}
}
driver program
code:
/****************************************************************
 * Author: Bullio
 *
 * Date Written: 5Dec2013
 *
 * Filename: BullioWeek6Prog.java
 *
 * Purpose: List cats that are over 3 and declawed after user inputs
 ***************************************************************/

import java.util.*;

public class BullionWeek6Prog {
	public static void main(String[] args) {

		Scanner keybd = new Scanner(System.in);
		Cat myCat1 = new Cat();
		Cat myCat2 = new Cat();
		Cat myCat3 = new Cat();


		System.out.println("Enter the name of Cat 1: ");
		myCat1.setName(keybd.nextLine());

		System.out.println("Enter the age of Cat 1: ");
		myCat1.setAge(keybd.nextInt());

		System.out.println("Enter the weight of Cat 1: ");
		myCat1.setWeight(keybd.nextDouble());
		String dummy = keybd.nextLine();

		System.out.println("Enter the breed of Cat 1: ");
		myCat1.setBreed(keybd.nextLine());

		System.out.println("Does the cat have claws? True or False?: ");
		String claws1 = keybd.nextLine();

		if (claws1.equalsIgnoreCase("false")) {
			myCat1.set(true);
		}

		System.out.println("Enter the name of Cat 2: ");
		myCat2.setName(keybd.nextLine());

		System.out.println("Enter the age of Cat 2: ");
		myCat2.setAge(keybd.nextInt());

		System.out.println("Enter the weight of Cat 2: ");
		myCat2.setWeight(keybd.nextDouble());
		String dummyAgain = keybd.nextLine();

		System.out.println("Enter the breed of Cat 2: ");
		myCat2.setBreed(keybd.nextLine());

		System.out.println("Does the cat have claws? True or False?: ");
		String claws2 = keybd.nextLine();

		if (claws2.equalsIgnoreCase("false")) {
			myCat2.set(true);
		}

		System.out.println("Enter the name of Cat 3: ");
		myCat3.setName(keybd.nextLine());

		System.out.println("Enter the age of Cat 3: ");
		myCat3.setAge(keybd.nextInt());

		System.out.println("Enter the weight of Cat 3: ");
		myCat3.setWeight(keybd.nextDouble());
		String dummylast = keybd.nextLine();

		System.out.println("Enter the breed of Cat 3: ");
		myCat3.setBreed(keybd.nextLine());

		System.out.println("Does the cat have claws? True or False?: ");
		String claws3 = keybd.nextLine();

		if (claws3.equalsIgnoreCase("false")) {
			myCat3.set(true);
		}

		System.out.println("Cats over 3 with claws are: ");

		if (myCat1.getAge() >= 3 && myCat2.getDeclawed() == false) {
			System.out.print(myCat1.getName() + "\n");
		}

		if (myCat2.getAge() >= 3 && myCat1.getDeclawed() == false) {
			System.out.print(myCat2.getName() + "\n");
		}

		if (myCat3.getAge() >= 3 && myCat3.getDeclawed() == false) {
			System.out.print(myCat3.getName() + "\n");
		}


	}//end main
}//end BullioWeek6Prog
The String dummy... lines are there because the keybd.nextDouble(); was causing it to skip the next question entirely.

It meets the requirements, so I should get a proper grade for it, but I was hoping I could learn from you guys what I could do better with the tools at my disposal. Also, what books would you recommend? I like Java, but I'm really only relying on it as a stepping stone to learn how to program before focusing on learning another language entirely. The posts I've read here have been way informative and I look forward to delving deeper into the programming world.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Code reuse is the biggest thing in programming, usually. Programmers are lazy, and they especially hate repeating themselves. There's a few things you can do here, if you make the Cat class yourself:

* take the code that reads in the input from the user to get the parameters fire the cat, and put it into it's own method. Have that method return a new Cat instance, which has the appropriate fields
* have that method live inside of the cat class, and return void, setting the instance values instead.
* create a constructor for Cat that is passed the input stream, and reads in the values that it needs to create itself

The idea is that you want to make a thing that will handle giving you a cat, so that you can call it an arbitrary number of times instead of copy/pasting your code and changing one value on each line.

Also, I believe that the Boolean class has a method to parse a string and return the appropriate boolean value.

Bullio
May 11, 2004

Seriously...

Volmarias posted:

Code reuse is the biggest thing in programming, usually. Programmers are lazy, and they especially hate repeating themselves. There's a few things you can do here, if you make the Cat class yourself:

* take the code that reads in the input from the user to get the parameters fire the cat, and put it into it's own method. Have that method return a new Cat instance, which has the appropriate fields
* have that method live inside of the cat class, and return void, setting the instance values instead.
* create a constructor for Cat that is passed the input stream, and reads in the values that it needs to create itself

The idea is that you want to make a thing that will handle giving you a cat, so that you can call it an arbitrary number of times instead of copy/pasting your code and changing one value on each line.

Also, I believe that the Boolean class has a method to parse a string and return the appropriate boolean value.

Awesome. I did do the Cat class myself.

So if I throw the user input code into the class file, I can write a method and word it something like public void userInput(); right? Where I'm lost is how do I accept user input? Would it go in the class file the way I have it assigning the data to the reference variable: myCat.setName(keybd.nextLine()); ?

By having the method return void, it'd be a mutator, right?

I just learned about constructors yesterday. Am I right in assuming it'd be something like (rough approximation):

code:
public myCat1(String a, int b, double c, string d)
{
 this.name = a;
 this.age = b;
 this.weight =c;
 this.breed = d;
}
If so, how do I get the boolean value assigned to it. I think I remember saying a boolean couldn't be set with a constructor. I could be wrong though.

I'm going to work on your first suggestion and see if I can figure it out. I get what you're saying, but I don't know exactly how to get it done. Place the user input lines in the class file in a method and at the end of the method, each time it's run, it should return a new cat instance. Would it be named properly? Also, how do I get it to say Cat 1, Cat 2, Cat 3 each succeeding time it runs the set of questions?

Like I said, it's already turned in and meets requirements, this is more for my personal education than anything. Thanks for your help and feel free to let me know when I'm starting to bug you with my stupid questions. In the meantime, I think I need to reread the last 2 chapters in an effort to get it to sink in better.

Edit, nix the boolean question. You said there was a way to parse a string and pass the appropriate value to the boolean. Would that be a wrapper class?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Bullio posted:

Awesome. I did do the Cat class myself.

So if I throw the user input code into the class file, I can write a method and word it something like public void userInput(); right? Where I'm lost is how do I accept user input? Would it go in the class file the way I have it assigning the data to the reference variable: myCat.setName(keybd.nextLine()); ?


Sort of. Something like:

code:
public class Cat {
  ...
  public void setFromInput(OutputStream os, InputStream is) {
    Scanner s = new Scanner(is);
    os.println("Enter cat name: ");
    setName(s.nextLine());
    os.println("Enter cat age: ");
    setAge(s.nextInt());
    ...
  }
  ...
}

quote:

By having the method return void, it'd be a mutator, right?

In the sense that it has a side effect, yes. The return value isn't really important here.

quote:

I just learned about constructors yesterday. Am I right in assuming it'd be something like (rough approximation):

code:
public myCat1(String a, int b, double c, string d)
{
 this.name = a;
 this.age = b;
 this.weight =c;
 this.breed = d;
}
If so, how do I get the boolean value assigned to it. I think I remember saying a boolean couldn't be set with a constructor. I could be wrong though.

Not quote. The syntax of constructors is that the name is the same as the class. I was suggesting for your edification something like:

code:
public class Cat {
  ...
  public Cat(OutputStream os, InputStream is) {
    Scanner s = new Scanner(is);
    os.println("Enter cat name: ");
    setName(s.nextLine());
    os.println("Enter cat age: ");
    setAge(s.nextInt());
    ...
  }
  ...
}
It's ok to call member methods within the constructor.

quote:

I'm going to work on your first suggestion and see if I can figure it out. I get what you're saying, but I don't know exactly how to get it done. Place the user input lines in the class file in a method and at the end of the method, each time it's run, it should return a new cat instance. Would it be named properly? Also, how do I get it to say Cat 1, Cat 2, Cat 3 each succeeding time it runs the set of questions?

Like I said, it's already turned in and meets requirements, this is more for my personal education than anything. Thanks for your help and feel free to let me know when I'm starting to bug you with my stupid questions. In the meantime, I think I need to reread the last 2 chapters in an effort to get it to sink in better.


quote:

Edit, nix the boolean question. You said there was a way to parse a string and pass the appropriate value to the boolean. Would that be a wrapper class?

I meant Boolean.parseBoolean

So, if I were going to write this myself, it would probably be something more along the lines of:

code:
public class Cat {

  private String breed;
  private boolean declawed;
  private String name;
  private int age;// in years
  private double weight;// in pounds

  public Cat(String breed, boolean declawed, String name, int age, double weight) {
    setBreed(breed);
    setDeclawed(declawed);
    ...
  }

  // getters and setters as before.
  ...

  public String toString() {
    return "A cat named " + getName();
  }
}

public class UsefulThingsGoHere {

  static Cat askAndGetCat(Scanner s, OutputStream os) {
    String breed = askAndGetBreed(s, os);
    int age = askAndGetAge(s, os);
    ...
    return new Cat(breed, declawed, name, age, weight);
  }

  static String askAndGetBreed(Scanner s, OutputStream os) {
    os.println("Enter the breed of cat: ");
    return s.nextLine();
  }

  static int askAndGetAge(Scanner s, OutputStream os) {
    os.println("Enter the age of cat: ");
    return s.nextInt();
  }

  // Other methods to ask and get things
  ...

  static final int DEFAULT_CAT_COUNT = 3;

  public static void main(String... args) {
    Scanner s = new Scanner(System.in);
    
    int catCount = DEFAULT_CAT_COUNT;
    if(args.length > 0) {
      try {
        catCount = Integer.parseInt(args[0]);
      } catch (NumberFormatException ex) {
        // Nope, not the cat count. Ignore it for this proof of concept.
      }
    }

    List<Cat> catList = new ArrayList<Cat>();
    for(int i = 0; i < catCount; i++) {
      catList.add(askAndGetCat(s, System.out);
    }

    for(Cat c : catList) {
      if(!c.getDeclawed() && c.getAge >= 3) {
        System.out.println(c);
      }
    }
  }
}

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Bullio posted:

If so, how do I get the boolean value assigned to it. I think I remember saying a boolean couldn't be set with a constructor. I could be wrong though.

boolean can't be constructed because it isn't an object, correct!

But Boolean is an object and can be!

You can then save that Boolean as a Boolean or as a boolean, because java has autoboxing (syntactic shorthand, the compiler will convert to wrapper classes and back automatically, since they're obvious)

Java code:
//plain data is not an object
boolean bData = false;
//wrapper class is an object
Boolean bObj = new Boolean();
//we can autobox a Boolean into a boolean
bData = new Boolean();
//or we can autobox a boolean into a Boolean
bObj = false;
//but you can't call new on a PDT (plain data type)
bData = new boolean(); //this is an error
bObj = new boolean(); //also error can't do either

Bullio posted:

Edit, nix the boolean question. You said there was a way to parse a string and pass the appropriate value to the boolean. Would that be a wrapper class?

The big B Boolean is a class which is a wrapper to little b basic data type boolean, yeah. And the parse method is a static method (you don't need a big B boolean instance to call it) that takes a String and returns a Boolean.

So there's a class in java like
Java code:
public class Boolean
{
private boolean value;

public Boolean(){ ... }
public Boolean(boolean b){...}
...
//something like this
private static boolean parse(String input){
   if(input.equals("True")){
   return true;
   }
   return false;
}
}
}
Boolean sure is a silly word. Boolean Boolean Boolean.

Zaphod42 fucked around with this message at 05:54 on Dec 11, 2013

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

Bullio posted:

It meets the requirements, so I should get a proper grade for it, but I was hoping I could learn from you guys what I could do better with the tools at my disposal. Also, what books would you recommend? I like Java, but I'm really only relying on it as a stepping stone to learn how to program before focusing on learning another language entirely. The posts I've read here have been way informative and I look forward to delving deeper into the programming world.

Effective Java is a great Java book, as is Java Concurrency in Practice. The thing is, I'm not sure whether they'd be of a whole lot of use to you at this point; they expect kind of a lot of background knowledge that you just don't have yet, and they give you guidelines to solve problems that are beyond your skillset. Honestly, I'd probably go with the official Java Tutorials, paying a whole lot of attentions to "Getting Started" and "Language Basics." Having a very strong grasp of "Collections" is essential; these are your bread-and-butter tools for everyday programming. Date and Time functions are... well... there. Java's built-in Date object really isn't that great, tbh. (All the cool kids use the JodaTime library.)

And don't discount Java completely; it's not the newest, hottest language, but it is mature, which means that a lot of us make a living writing Java code. There are libraries to do basically anything in Java, and tools that work well surrounding the platform. A good programmer is language-agnostic; they'll be able to write in basically any language, given a while to study up on it, and have two or three at their fingertips to perform a wide variety of tasks. Having been on the interview-loop for a while, at my company we're looking for developers who are solid in any language, have a decent grasp of a scripting language to do simple tasks, and are familiar enough with bash to do very simple tasks without even writing a program in the first place.

Bullio
May 11, 2004

Seriously...

Volmarias posted:



code:
public class Cat {
  ...
  public void setFromInput(OutputStream os, InputStream is) {
    Scanner s = new Scanner(is);
    os.println("Enter cat name: ");
    setName(s.nextLine());
    os.println("Enter cat age: ");
    setAge(s.nextInt());
    ...
  }
  ...
}

I haven't come across the setFromInput or Output/InputStream before, but I'm going to save these posts in Evernote so I can refer to them when I do encounter those method calls. I am grateful for the examples and I know you're making an effort to dumb it down a bit for me, so thank you. The only thing we did with constructors in class was along the lines with what I posted, so learning you can call member methods from within was enlightening. It seems the more I learn, the more I don't know. I just took my final, but there's one more program and up to 3 more extra credit we can work on, so I think I figured out what I'm doing all day this Saturday. Been a bit too busy during the week to get in front of a computer for any proper length of time.


Zaphod42 posted:

boolean can't be constructed because it isn't an object, correct!

But Boolean is an object and can be!

You can then save that Boolean as a Boolean or as a boolean, because java has autoboxing (syntactic shorthand, the compiler will convert to wrapper classes and back automatically, since they're obvious)


Boolean sure is a silly word. Boolean Boolean Boolean.

That last line made me laugh hard. You wear the Zaphod name well. As far as finding out Boolean can be an object. . .mind blown. I wasn't aware of that at all. In your explanation, you said Java will convert between wrapper classes and primitive types automatically, so does that mean it doesn't matter whether I capitalize boolean in my declarations? In all honesty, I'm think I'm starting to reach the limits of my understanding. This semester covered a few basics, looping structures (which have a complexity that I don't think I've scratched the surface of), operands, increment and decrement operands, a few basic classes (i.e. math), skimmed across wrapper classes, and starting fiddling around with oop. I think at this point, I need to start spending some hours in tutorials to reinforce and expand on those techniques because it's still kind of easy to get lost. I really do appreciate your help though, for everything I don't understand I'm learning two new things.


Gravity Pike posted:

Honestly, I'd probably go with the official Java Tutorials, paying a whole lot of attentions to "Getting Started" and "Language Basics." Having a very strong grasp of "Collections" is essential; these are your bread-and-butter tools for everyday programming. Date and Time functions are... well... there. Java's built-in Date object really isn't that great, tbh. (All the cool kids use the JodaTime library.)

Thank you for this. This is what I'm going to do with my break over the holidays. I'm hoping they'll help me get to a level of understanding where I can just breeze through the assignments next semester and, even if they don't, they'll keep me in practice and keep the knowledge fresh in my head so I'll be ready to continue expanding on it when the next semester does start.

quote:

And don't discount Java completely; it's not the newest, hottest language, but it is mature, which means that a lot of us make a living writing Java code. There are libraries to do basically anything in Java, and tools that work well surrounding the platform.

I didn't mean to make it sound like I was. I've always been tangentially interested in programming without really knowing anything about it, so I'd lurk here and there and read posts and marvel at all the amazing things people were doig that I didn't understand. One reoccurring theme throughout most of the conversations I'd seen was that Java was mostly disliked. Maybe it was the wrong impression, regardless, I'm still be excited to be learning any language. I thought programming would be beyond me forever.

quote:

A good programmer is language-agnostic; they'll be able to write in basically any language, given a while to study up on it, and have two or three at their fingertips to perform a wide variety of tasks. Having been on the interview-loop for a while, at my company we're looking for developers who are solid in any language, have a decent grasp of a scripting language to do simple tasks, and are familiar enough with bash to do very simple tasks without even writing a program in the first place.

This. This is honestly where I want to get. The whole concept of programming thrills me and maybe even gives me a bit of a god complex. After all, you're creating something from nothing. At least that's how I see it. Point is, I wish I could live long enough to learn everything.

Also, what is bash? The closest thing I can think of is this site called bash.org. Is it a programming style?

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.
Bash is the default linux terminal. Knowing how to pipe together simple commands like grep, sed, sort, uniq, wc in order to filter and reduce data is a very important skill to practice. Not a day goes by where I don't do something like log onto a load-balancer and, grep ' 500 ' load_balancer.log.2013-12-01* | grep -oP 'userid/\w+' | sort | uniq | wc -l to figure out how many unique users were affected by server errors in a given day. (Roughly, "Search through all files starting with load_balancer.log.2013-12-01 for lines containing ' 500 ', then take the parts of those lines that are the string 'userid/' followed by any number of letters and numbers, and then sort those alphabetically, and then remove duplicates, and then count the number of lines.") You could have written a Java program to do that, but you'd waste a whole lot of time worrying about things like reading from files, and looking up how to do directory manipulation, and deciding on data structures, and saving your code somewhere, and compiling, when you could have taken thirty seconds on the command line to do the same thing using tools that someone else already wrote.

Command line skills are a bit harder to pick up than programming, because there's often not a class that specifically teaches them. On the other hand, each command tends to be very simple, and you only need to know a few commands in order to accomplish 90% of what you'd ever want to do from the command line.

Bullio
May 11, 2004

Seriously...

Gravity Pike posted:

Bash is the default linux terminal. Knowing how to pipe together simple commands like grep, sed, sort, uniq, wc in order to filter and reduce data is a very important skill to practice. Not a day goes by where I don't do something like log onto a load-balancer and, grep ' 500 ' load_balancer.log.2013-12-01* | grep -oP 'userid/\w+' | sort | uniq | wc -l to figure out how many unique users were affected by server errors in a given day. (Roughly, "Search through all files starting with load_balancer.log.2013-12-01 for lines containing ' 500 ', then take the parts of those lines that are the string 'userid/' followed by any number of letters and numbers, and then sort those alphabetically, and then remove duplicates, and then count the number of lines.") You could have written a Java program to do that, but you'd waste a whole lot of time worrying about things like reading from files, and looking up how to do directory manipulation, and deciding on data structures, and saving your code somewhere, and compiling, when you could have taken thirty seconds on the command line to do the same thing using tools that someone else already wrote.

Command line skills are a bit harder to pick up than programming, because there's often not a class that specifically teaches them. On the other hand, each command tends to be very simple, and you only need to know a few commands in order to accomplish 90% of what you'd ever want to do from the command line.

That's pretty awesome. Thank you. I guess I should download a version of linux and start fooling around with it as well then.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Bullio posted:

That's pretty awesome. Thank you. I guess I should download a version of linux and start fooling around with it as well then.

It can't hurt. Linux is fun because you can get the source code to most everything and build it yourself, so you can poke around and see how things are done, or make changes. Windows, everything is proprietary, you just flat out can't see the code ever to almost anything.

If you have a mac, OSX is totally POSIX so you can just learn on that instead of bothering with Linux. Its terminal is pretty good.

Alternatively you can install a linux shell in windows if you'd rather not deal with setting up partitions and a new OS. But it doesn't hurt to try a new OS, and some flavors of Linux like Ubuntu are really easy to set up compared to the old days.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Bullio posted:

I haven't come across the setFromInput or Output/InputStream before, but I'm going to save these posts in Evernote so I can refer to them when I do encounter those method calls. I am grateful for the examples and I know you're making an effort to dumb it down a bit for me, so thank you. The only thing we did with constructors in class was along the lines with what I posted, so learning you can call member methods from within was enlightening. It seems the more I learn, the more I don't know. I just took my final, but there's one more program and up to 3 more extra credit we can work on, so I think I figured out what I'm doing all day this Saturday. Been a bit too busy during the week to get in front of a computer for any proper length of time.

setFromInput is just a name that I made up. InputStream and OutputStream are very important, as they're the base classes relevant for almost any lower level I/O that you do. System.in is actually an InputStream, and System.out is actually an OutputStream. This is important to understand, because by default they point to the console input/output, but they can be reassigned to other things. For example, you could write a test that provides your own input and verifies what the output is.

quote:

That last line made me laugh hard. You wear the Zaphod name well. As far as finding out Boolean can be an object. . .mind blown. I wasn't aware of that at all. In your explanation, you said Java will convert between wrapper classes and primitive types automatically, so does that mean it doesn't matter whether I capitalize boolean in my declarations? In all honesty, I'm think I'm starting to reach the limits of my understanding. This semester covered a few basics, looping structures (which have a complexity that I don't think I've scratched the surface of), operands, increment and decrement operands, a few basic classes (i.e. math), skimmed across wrapper classes, and starting fiddling around with oop. I think at this point, I need to start spending some hours in tutorials to reinforce and expand on those techniques because it's still kind of easy to get lost. I really do appreciate your help though, for everything I don't understand I'm learning two new things.

The Boolean object is not actually the same thing as the boolean primitive. Translating between the two automatically is called Autoboxing, but it's important to realize that object versions of primitives exist for when an Object has to be provided for something, which also means that said object reference can be null. You should understand that there is a difference between primitives and objects, before you gleefully start mixing the two.

I want to reiterate the suggestion of reading the official java tutorials. It's OK that not everything makes sense at this point, because you're still new to programming, but it will help you move a little faster if you're ready to learn more, and honestly it's probably going to be organized better than whatever book you're learning from.

Volmarias fucked around with this message at 12:50 on Dec 12, 2013

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
Be very careful about autoboxing and comparing equality.

Java code:
public class Foo {

	public static void main(String[] args) {
		Integer x = 1;
		Integer y = 1;
		System.out.println(x == y);

		Integer a = new Integer(1);
		Integer b = 1;
		System.out.println(a == b);

		Integer foo = 128;
		Integer bar = 128;
		System.out.println(foo == bar);
	}
}
Output:

true
false
false

The first example may lead you to believe that == works everywhere on Integers, but you would be wrong, as you can see by the second and third example.

This is due to the wording of Integer.valueOf(int) method:

Returns an Integer instance representing the specified int value. If a new Integer instance is not required, this method should generally be used in preference to the constructor Integer.Integer(int), as this method is likely to yield significantly better space and time performance by caching frequently requested values. This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range.

Using .equals() will work on all of these. Null values can cause either option to throw an exception.

We've run into problems with this more than once, because we mix Integer (object) values coming from our ORM with int (primitive), and == sometimes works and sometimes doesn't, causing unexpected behavior.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.
Java code:
System.out.println(((Integer)foo).equals(bar));
At least that's always safe :) I just avoid == unless you're certain both are PDTs.

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
Well if either side of an == is a primitive, then the Object is auto-unboxed and == works as expected for the primitive types.

Just be careful about the Object being null. But if the object is null, and you put it on the left side of the .equals(), it would throw the same NPE.

Smarmy Coworker
May 10, 2008

by XyloJW
So. Readers/writers.

I'm trying to set my reader encoding to ANSI but it doesn't seem to want to actually read escape characters.

pre:
To request a character:
  request <player_name> for <email_address>
To connect with an existing player: 
  connect <player> <password>
If you forgot your password: 
  password <player> for <email_address>
This is the output to my window. It's a JTextArea so that I can select/copy from it. This might be part of the problem but I have no idea honestly. The text between the color codes should be bolded.

Java code:
public class connector {
	
	private InputStreamReader fromServer;
	private OutputStreamWriter toServer;
	private String encoding = "Cp1252";
	
	/**
	 * Constructs connector; creates socket and readers/writers to designated MUD server
	 * @param servername server address
	 */
	public connector(String servername) {
		connectToServer(servername);
	}

	/**
	 * Creates socket and stream reader/writer for socket. Starts up input thread.
	 * @param servername server address
	 */
	private void connectToServer(String servername) {
		try {
				// Create a socket to connect to the MOO server
				Socket socket = new Socket(servername, 7777);

				// Create an input stream to receive data from the server
				fromServer = new InputStreamReader(socket.getInputStream(), encoding);

				// Create an output stream to send data to the server
				toServer = new OutputStreamWriter(socket.getOutputStream(), encoding);
		} catch (Exception ex) {
			System.err.println(ex);
		}
	}
}
Beginning of my connector class where the stream stuff happens.

Java code:
public class inputThread extends Thread {

	private BufferedReader fromServer;
	private gameWindow game;
	
	public inputThread(connector parent, gameWindow game) {
		super();
		
		// Set up reader
		fromServer = new BufferedReader(parent.getInput());
		this.game = game;
	}
	
	public void run() {
		try {
			
			// Attempt to read from stream and send text to game window.
			do {
				game.receiveText(fromServer.readLine());
			} while(true);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
Input thread.


Not entirely sure what I should be doing. Windows telnet client receives the ANSI escapes and whatnot just fine, so I was thinking I could connect using Apache's telnet library, but I don't really want to depend on any external libraries for such a small program.


I could theoretically parse ANSI output on my own, but this creates a problem where players connected to this game can say things with ANSI codes in them where the escape character is itself automatically escaped. By reading ANSI through the stream, this would display as intended (ex. Bob says, "~1b[1m") but my own parsing would have him say nothing and bold every following line.

Smarmy Coworker fucked around with this message at 00:06 on Dec 13, 2013

crunk dork
Jan 15, 2006
What are some good resources if I'm wanting to teach myself Java? I have seen several tutorials on how a to accomplish certain tasks but I'm more interested in a textbook or something else that's structured with lessons, exercises, reviews, etc. I've read a lot of good things about "Thinking In Java" and am considering ordering it.

crunk dork fucked around with this message at 03:01 on Dec 13, 2013

Pollyanna
Mar 5, 2005

Milk's on them.


Has anyone run into the "Project folder exists and is not empty" issue with NetBeans? I've deleted the userdir and the project directories, but this problem still crops up. What do I need to do to fix it?

dr cum patrol esq
Sep 3, 2003

A C A B

:350:

Drunk Orc posted:

What are some good resources if I'm wanting to teach myself Java? I have seen several tutorials on how a to accomplish certain tasks but I'm more interested in a textbook or something else that's structured with lessons, exercises, reviews, etc. I've read a lot of good things about "Thinking In Java" and am considering ordering it.

If you have no experience Greenfoot is excellent.

crunk dork
Jan 15, 2006

front wing flexing posted:

If you have no experience Greenfoot is excellent.

The shameful part is I actually have an AAS in Information Systems but I feel like all I was taught in school was basic syntax, I graduated a year ago and didn't really pursue it so now that I've forgotten the little bit I did learn I decided it's time to start taking it more seriously. Greenfoot doesn't look like a bad place to start though, thanks!

Woodsy Owl
Oct 27, 2004
I did some searching around but I couldn't come up with a consensus to this question: is it considered bad form to have multiple packages in a single project? I am working on a new project and many of the classes have some reuse value, and I'm relatively sure I will use them in the future. So, while I am developing those classes, I want to define them in a separate package within my project. Then, when I need to reuse the classes in that package it will be trivial to move them into their own project.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Woodsy Owl posted:

I did some searching around but I couldn't come up with a consensus to this question: is it considered bad form to have multiple packages in a single project? I am working on a new project and many of the classes have some reuse value, and I'm relatively sure I will use them in the future. So, while I am developing those classes, I want to define them in a separate package within my project. Then, when I need to reuse the classes in that package it will be trivial to move them into their own project.

It is good, and even encouraged, to have multiple packages. You might make them sub packages, of course.

com.woodsyowl.dickbutt
com.woodsyowl.dickbutt.parser
com.woodsyowl.dickbutt.horsecocks

However, you should also be happy to put common functionality that other projects would use into their own package, so that they don't need the dickbutt application for that functionality. These are two distinct considerations.

Volmarias fucked around with this message at 06:05 on Dec 16, 2013

Doctor w-rw-rw-
Jun 24, 2008

Woodsy Owl posted:

I did some searching around but I couldn't come up with a consensus to this question: is it considered bad form to have multiple packages in a single project? I am working on a new project and many of the classes have some reuse value, and I'm relatively sure I will use them in the future. So, while I am developing those classes, I want to define them in a separate package within my project. Then, when I need to reuse the classes in that package it will be trivial to move them into their own project.
Smartly organized packages are a huge plus. Personally, I go ask far as I like in building package hierarchies, because it's so easy to go back and rearrange them to something sensible. Too many Java programmers IMO fail to use packages as meaningful clues to other developers.

That said, /smartly/ organized is different than /strictly/ organized. It's just that refactoring tools make rearranging or whittling down lots of packages easy.

Woodsy Owl
Oct 27, 2004

Doctor w-rw-rw- posted:

Smartly organized packages are a huge plus. Personally, I go ask far as I like in building package hierarchies, because it's so easy to go back and rearrange them to something sensible. Too many Java programmers IMO fail to use packages as meaningful clues to other developers.

That said, /smartly/ organized is different than /strictly/ organized. It's just that refactoring tools make rearranging or whittling down lots of packages easy.

With regards to source control, would you want a separate repository for each sub-package? My projects are starting to intersect in that they end up using some classes that I've written prior. Is there a decent write-up detailing smart and effective package organization?

edit: Derp, http://docs.oracle.com/javase/tutorial/java/package/index.html

Woodsy Owl fucked around with this message at 16:04 on Dec 16, 2013

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

Woodsy Owl posted:

With regards to source control, would you want a separate repository for each sub-package? My projects are starting to intersect in that they end up using some classes that I've written prior. Is there a decent write-up detailing smart and effective package organization?

edit: Derp, http://docs.oracle.com/javase/tutorial/java/package/index.html

Nah that's way too many repositories and too much work. You probably just want one single repo, with seperate folders for each project, and code organized under project src folders based on package. If a package is used in a seperate project, you'll want to copy the source code to the new project folder so they're separate, or better yet, create a third project that has the common code and compiles to a library, and then copy that library to the other two projects after compilation and import it.

Maybe you have some branches for different release versions or something, but not per package, nahhh.

Projects should be able to pull from tons of different resources without any conflicts.

FateFree
Nov 14, 2003

I'm working on a large application that's locked into a terrible database that cannot perform. All of our queries are hitting an 'Index' table, which is a simple table with three columns: customerId, indexName, indexValue. It might contain things like: 1, FirstName, John - and a search by name query would be something like Select customerId from Index where indexName=FirstName and indexValue=John. The customerId is later joined to another set of tables.

Changing the database is not an option - but we are able to move the indexing off of the database onto something else. I'm looking for the best suggestion. Right now we are considering Lucene, because some of the indexed fields require fuzzy searching. However there is very little document searches, we really only have name/value pairs that link back to a customer.

Is there anything more practical than Lucene for this kind of indexing? We essentially just need a quicker way to maintain an index since our database can't do it.

hooah
Feb 6, 2006
WTF?
I'm trying to follow Stanford's Intro to Programming course to learn Java. However, there seems to be a problem with their distribution of Eclipse for Windows (here), or perhaps it just doesn't work well with Windows 8. When I try to run that, I get this hideous mess of errors that I don't understand. Could someone help me get this working?

I also tried using standard Eclipse, but couldn't get a Karel the Robot project working with it.

pigdog
Apr 23, 2004

by Smythe

FateFree posted:

I'm working on a large application that's locked into a terrible database that cannot perform. All of our queries are hitting an 'Index' table, which is a simple table with three columns: customerId, indexName, indexValue. It might contain things like: 1, FirstName, John - and a search by name query would be something like Select customerId from Index where indexName=FirstName and indexValue=John. The customerId is later joined to another set of tables.

Changing the database is not an option - but we are able to move the indexing off of the database onto something else. I'm looking for the best suggestion. Right now we are considering Lucene, because some of the indexed fields require fuzzy searching. However there is very little document searches, we really only have name/value pairs that link back to a customer.

Is there anything more practical than Lucene for this kind of indexing? We essentially just need a quicker way to maintain an index since our database can't do it.

Sounds like you might benefit from changing your database schema to something more sensible, but even so, I bet there are ways to optimize that table. What database IS it and what kind of actual indexes are there on the "Index" table?

Lucene probably isn't what you're looking for, as it's designed to look for info from self-contained documents (such as for example forum posts) and isn't very good at joins. For relational data it's just fine to use a relational database.

Volguus
Mar 3, 2009

FateFree posted:

I'm working on a large application that's locked into a terrible database that cannot perform. All of our queries are hitting an 'Index' table, which is a simple table with three columns: customerId, indexName, indexValue. It might contain things like: 1, FirstName, John - and a search by name query would be something like Select customerId from Index where indexName=FirstName and indexValue=John. The customerId is later joined to another set of tables.

Changing the database is not an option - but we are able to move the indexing off of the database onto something else. I'm looking for the best suggestion. Right now we are considering Lucene, because some of the indexed fields require fuzzy searching. However there is very little document searches, we really only have name/value pairs that link back to a customer.

Is there anything more practical than Lucene for this kind of indexing? We essentially just need a quicker way to maintain an index since our database can't do it.

What do you mean by cannot perform? Has that index table indexes created for the indexName and indexValue fields? Such as CREATE INDEX IDX1 on Index (indexName,indexValue) ? Is customerId a primary key on the other tables? Or has an index made for it?

However you look at it though, the existence of the Index table doesn't look good. Changing the database may not help in this case. Changing the developers may.

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


It sounds like what you're really looking for is a DBA.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

hooah posted:

I'm trying to follow Stanford's Intro to Programming course to learn Java. However, there seems to be a problem with their distribution of Eclipse for Windows (here), or perhaps it just doesn't work well with Windows 8. When I try to run that, I get this hideous mess of errors that I don't understand. Could someone help me get this working?

I also tried using standard Eclipse, but couldn't get a Karel the Robot project working with it.

I don't have windows 8 so I don't know of its horrors, but you should be fine just using the normal Eclipse for Windows devs from the Eclipse page.

What was your problem with getting "Karel the Robot" to work with it? You're probably just not familiar with Eclipse, which I guess is why Stanford had a special build of Eclipse packaged ready to go. You'll just have to import the right project and make sure the build path is properly configured.

hooah
Feb 6, 2006
WTF?

Zaphod42 posted:

I don't have windows 8 so I don't know of its horrors, but you should be fine just using the normal Eclipse for Windows devs from the Eclipse page.

What was your problem with getting "Karel the Robot" to work with it? You're probably just not familiar with Eclipse, which I guess is why Stanford had a special build of Eclipse packaged ready to go. You'll just have to import the right project and make sure the build path is properly configured.

Using the standard version of Eclipse, I followed the directions here to set up Karel with Eclipse. However, likely due to my brand-newness at Java, I couldn't figure out how to translate the importing and class setup for the program written in the second lecture into something that would work with the directions I linked above.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

hooah posted:

Using the standard version of Eclipse, I followed the directions here to set up Karel with Eclipse. However, likely due to my brand-newness at Java, I couldn't figure out how to translate the importing and class setup for the program written in the second lecture into something that would work with the directions I linked above.

That seems fine. If you've got the libraries imported, the 'second lecture program' you refer to should work. Namespaces are set up such that it shouldn't be machine specific.

So you're saying you've got the program that Stanford wants you to look at open in Eclipse, and Eclipse has the Karel external libraries imported.

So, whats the issue? You're getting a compilation error when you try to build the program?
Can you put the program on pastebin, or copy the output of the compiler error here for us? Need more information.

You may just have to make sure the library is imported for specifically that project. Alternatively Java's just complaining because your package name doesn't match the source folder or something, odds are you can just mouse over the red underline and Eclipse will suggest a fix for you. (Package name X should be Y, for example) Click the underlined text and it'll apply the fix automatically.

Zaphod42 fucked around with this message at 19:51 on Dec 18, 2013

hooah
Feb 6, 2006
WTF?

Zaphod42 posted:

That seems fine. If you've got the libraries imported, the 'second lecture program' you refer to should work. Namespaces are set up such that it shouldn't be machine specific.

So you're saying you've got the program that Stanford wants you to look at open in Eclipse, and Eclipse has the Karel external libraries imported.

So, whats the issue? You're getting a compilation error when you try to build the program?
Can you put the program on pastebin, or copy the output of the compiler error here for us? Need more information.

You may just have to make sure the library is imported for specifically that project. Alternatively Java's just complaining because your package name doesn't match the source folder or something, odds are you can just mouse over the red underline and Eclipse will suggest a fix for you. (Package name X should be Y, for example) Click the underlined text and it'll apply the fix automatically.

I think my problem lies in importing. Currently, my project hierarchy is
code:
MyProject
 |_src
 |  |_kareltherobot
 |      |_OurKarelProgram.java
 |_JRE System Library
 |_KarelJRobot.jar
My java file is as follows:
code:
package kareltherobot;

import KarelJRobot.jar.* // This probably isn't right
public class OurKarelProgram extends Karel{
	public void run() {
		move();
		turnLeft();
	}
}
I forgot to add that Eclipse has underlined KarelJRobot, the class name Karel, and of course the methods.

hooah fucked around with this message at 20:13 on Dec 18, 2013

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You don't need to import the .jar file - instead, you import the specific classes you want to use, and Eclipse uses your classpath setup to figure out where they are.

With the code you have right now, you should be able to delete that import line, and then if you hover your mouse over the "extends Karel" statement then Eclipse should offer to fix it for you by importing the Karel class.

Jabor fucked around with this message at 23:59 on Dec 18, 2013

hooah
Feb 6, 2006
WTF?

Jabor posted:

You don't need to import the .jar file - instead, you import the specific classes you want to use, and Eclipse uses your classpath setup to figure out where they are.

With the code you have right now, you should be able to delete that import line, and then if you hover your mouse over the "extends Karel" statement then Eclipse should offer to fix it for you by importing the Karel class.

The fixes I'm offered are "Create class 'Karel'", "Change to 'Kernel' (java.awt.image)", and "Fix project setup...", none of which does what you say.

Volguus
Mar 3, 2009

hooah posted:

The fixes I'm offered are "Create class 'Karel'", "Change to 'Kernel' (java.awt.image)", and "Fix project setup...", none of which does what you say.

you will want to choose fix project setup, and add that jar onto the project's classpath. then you will have it available.

Adbot
ADBOT LOVES YOU

hooah
Feb 6, 2006
WTF?

rhag posted:

you will want to choose fix project setup, and add that jar onto the project's classpath. then you will have it available.

Could you go into a little more detail? Keep in mind I've never worked with java or Eclipse before. Here's the dialog I see when I choose fix project:

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