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
Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

fret logic posted:

When I was thinking of the addition, I was implementing reducing to the lowest terms. This looks like it just multiplies the denominators and leaves it like that.

It says in the instructions that in the next project they will reduce the fraction to it's lowest terms. For now it's enough that they just keep multiplying the denominator.

Adbot
ADBOT LOVES YOU

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
If you can change your objects you can have them implement the Comparator interface. Now you can use the sort the function in java.util.Collections class.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I agree with posting your code. Your problem doesn't make much sense, it should work.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Well your approach isn't very OO yet. I'll try to critique your Player class first.

You are limiting yourself by defining the 2 playerclasses. A much more robust constructor would be this.

code:
public Player (int hitpoints, int strength, int defense, String playerclass){
    this.hitpoints = hitpoints;
    this.strength= strength
    this.defense, = defense, ;
    this.playerclass = playerclass;
}
Now in your main program you can create as many different characters classes as you wish or even variations of the same class. Imagine a Fighter with less hit points and higher defense. You could even allow the user to create their own class by giving them lets say 100 points to distribute between Strength, Defense, and HP. You can still use your approach and have some predefined classes that they can choose from. The choice is up to you but this constructor allows more flexibility later on.

Your method updateStats should be changed to override the toString method since you are not actually updating any of the stats.

I think the only method that is missing from the Player class is a combat method where he can do damage to another Player.

I'll let someone else comment on your GameLoop class because I have to run.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
There is Bruce Eckel's Thinking in Java which is available online for free. I've been reading his C++ book and I like it very much. I can't think of any Java tutorials, but frankly you should stay away from them. Tutorials rarely cover any subject in depth so there usefulness is limited.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Incoherence posted:

There's one catch: you'll want to check that each of your four/eight adjacent points are inside the matrix, but what you want to do about that will depend on whether you want to wrap around on edges or just drop them.

I've always wondered what people do when you just want to drop them. In the past I've surrounded that block of code with a try/catch that doesn't do anything when an IndexOutOfBoundsException is thrown.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Incoherence posted:

If I ever saw anyone use a try/catch I'd go put it in the Coding Horror thread posthaste.

You are right, I was too quick to post. Here is what I actually meant, I had an algorithm that would traverse the array diagonally. The problem I had was dealing with 01, 02, 04, 06, 08, and 09. So I put it in a try catch and let it keep doing it's thing.


01 02 03
04 05 06
07 08 09



As I posted this I realized that I could check to see if it was out of bounds and just use the continue statement. :doh:

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Maybe he means calling the pack method on the window.
Window.pack()

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
When my kids start learning how to use objects I go out of my to explain this to them. But yeah I don't think the Deitel book even offers an explanation.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I discovered something awesome about java today! Labeled loops

I had a triple nested loop and the two inner loops were traversing the same data structure. I wanted to be able to break out of two loops and using a flag for this kind of stuff annoys me. I did a quick search and found the labeled loops. After reading some more I realized that you can label any block of code and effectively have a goto! It seems like it could be misused, but I'm happy with what I used it for.

code:
label: for(.....)
           for(....)
               break label;

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Well if you assume that a person can't have a number in his name and that the student ID is made up of all numbers then you can reasonably separate the fields. The hardest part would be separating the ID from the email since an email can start with a number, so there would have to be some whitespace between the id and the email.

Janitor Prime fucked around with this message at 05:09 on May 23, 2008

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Led posted:

I don't know if this is the right thread, but does anyone want to test my Java applet for me ?
I heard some people had problems with it, especially on other operating systems.
(I've only tested it locally on windows)

it's at http://www.supercheckmate.com (but it has nothing to do with chess :))

Well it loads and works on my Kubuntu 8.0.4 x64 machine. Also it said that a picture of a flower was indecent. :confused:

edit: I forgot to mention I'm running Sun's Java 6 and Firefox 2 on this computer.

Janitor Prime fucked around with this message at 20:52 on May 28, 2008

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Well another problem with your code is that you trying to save their name as an int when you should be saving them as Strings. The only things that are ints are their age and height. You should also tell them to specify their height in inches, that way you don't have to parse feet and inches.

You are also missing the types for the fields first, last, hieght, gender, and your drivers license field is repeating.


edit: About JCreator, don't worry about the black box, your output will be in a small white box at the bottom of the screen. The reason you can't type in it is because of all the compiler errors I mentioned above.

Janitor Prime fucked around with this message at 13:04 on Aug 6, 2008

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
That's loving retarded, why would you ever want that.

Since your fields aren't private and they are all in the same package, I think you should be able to access each one's X by placing the class name dot x.

TestClass.x NestedTest.x NestedNestedTest.x and x

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Maybe the super keyword can help you. I don't know if it actually works for anything other than methods.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Java 6 comes with derby now if that means anything.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I have a question about find bugs, it reports a possible NullPointer on the bolded line.

code:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		while (true) {
			String input = null;
			System.out.println("Please enter an expression\n");
			try {
				input = in.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.exit(1);
			}			
[b]			if(input.equalsIgnoreCase("quit") || input.equalsIgnoreCase("exit")){[/b]
				break;
			}
I'm not sure if that's a real warning or just a false positive.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Mustach posted:

The lesson is that everything that depends on input should be in the try block:
code:
try{
  input = in.readLine();
  if(input.equalsIgnoreCase("quit") || input.equalsIgnoreCase("exit"))
    break;
  // ...
}catch (IOException e){
  // ...

Duh. Thank you for clearing that up.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

zootm posted:

I'd consider this pretty bad style - it's usually best to avoid putting code that doesn't throw a given exception in a 'try' block which catches it. Removing the '= null' from the variable declaration will cause the compiler to check that any control flow to a line where you use the variable definitely assigns it.

There's two other problems here though - the compiler may not recognise that System.exit terminates control flow (although really avoiding that function is the best solution for that). The other problem is that FindBugs may not think that 'readLine' returns a non-null value.

What would be another way to terminate flow? Just a simple return?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Flamadiddle posted:

It's just that the use of the database makes what we want to do much simpler. Would it make more sense to make a call to a server side application or something to seperate the user from the database?

This is the correct way to do it, you don't want random people on the internet to have direct access to your database.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Flamadiddle posted:

My applet will just be a GUI for people to enter the message and that'll just get passed to the server.

Honestly a simple html form is all you need. No need to even make an applet.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
If you look at the String API, you'll see that there is no such method as doubleValue(). What you need to do is use the Double class to parse your strings like so.
code:
double taxfed = ( Double.parseDouble(fed) * Double.parseDouble(gross) );

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

LakeMalcom posted:

If order matters, then roll your own little map to put and get the reverse order string.

The TreeMap lets you take ordering into account.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Incoherence posted:

Hm, somehow missed this earlier.
Ow, my brain hurts. If you're working on a project of even moderate size, an important aspect of working together is being able to use a coherent style (so you can read each other's code), and commenting your code (so you can understand each other's code, or you can understand your own code 3 months from now). While students hate this because it seems silly to write 5 lines of comments for a 3 line function, it's For Your Own Good (tm) and someday you'll be glad you commented this cute trick you pulled in one method way off in a corner of the project.

My only counter argument to this, how often do you go back and look at your own code from semesters past?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
First of all you should be using generics, it makes your code much easier to work with since you don't have to cast your objects all the time. This has some other benefits like preventing accidentally adding an object that isn't a Calc into your arraylist.

code:
ArrayList<Calc> calcs = new ArrayList<Calc>();
Second you need to make getter and setter methods for each of those fields if you want to be able to modify them.

code:
public class Calc { 
private String Name; 
private String Quantity; 
private String Units;

    public String getQuantity(){
        return Quantity;
    }

    public void setQuantity(String Quantity){
        this.Quantity = Quantity;
    }
    ....
}
Then you can do things with those objects in your for loop.

Janitor Prime fucked around with this message at 04:55 on Oct 28, 2008

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
quote != edit

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
You shouldn't compare objects with ==. Trying using the .equals method of the string.

if( direction.equals("E") )

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Create another class, not an anonymous class, that receives an integer in it's constructor.
code:
public class blah{

    private static final String[] buttonNames = { "Red", "Green", "Blue" }; 

    public void Constructor(){
        for (int i = 0; i < 3; i++){
            buttons[i].addActionListener(new ButtonListener (i));
        }
    }
}

class ButtonListener extends ActionListener{
    private int i;
    public ButtonListener(int i){
        this i = i;
    }

    public void actionPerformed(ActionEvent event){ 
        Icon planet = new ChangeIcon(150, 150, blah.buttonNames[this.i]);
        label.setIcon(planet); 
        label.repaint(); 
    } 
Also you should change that array of buttonNames at the top to an enum.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Eclipse is written using SWT, so I would imagine it has a nice SWT designer. Maybe you overlooked it.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Lets look at the Java API for the String class.

code:
public String substring(int beginIndex, int endIndex)
          Returns a new string that is a substring of this string.
It has a member method called substring that receives two integers, the beginning offset and the end offset. The question is asking you if the substring method receives the string that will be searched, so it is false.

In order to call this method you have to have an existing String object like so:
code:
String s = "Check this out.";
String sub = s.substring(0,5);
And sub would have the value of "Check"



If the statement in the question were true then in the API there would be a static method in the String class that received a String like so:
code:
public static String substring(String original, int beginIndex, int endIndex)
          Returns a new string that is a substring of original string.
Here is how this hypothetical method would be used:
code:
String sub = String.substring("Check this out",0,5);

Janitor Prime fucked around with this message at 23:19 on Dec 16, 2008

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Logostomp posted:

Am I really hurting anybody by asking a question? I'm not asking for the answer. Just asking for some help.

But you are not asking for help, you are asking for us to do your homework. An example of asking for help would be, "How should I store all the numbers as they come in?". Your so called question can be answered by a 1 second google search, you already know how to compare 2 numbers.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Ant is another alternative to Maven and a lot of projects still use ant.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

jstirrell posted:

Poker Stuff

Any help would be greatly appreciated!

I didn't get a chance to look at your code, but with a quick glance I noticed you had a lot of constants in your code. Read up on Enums, they replaced the public static int paradigm. As a bonus, that tutorial has some code for creating a poker deck! Some of the code might be over your head so feel free to ask us any questions about it.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
The way your class is right now won't let you take advantage of the toString method because you hardcoded the number of sides. So what you should do is declare a variable called sides and define it as 4 in the square and 12 in the cube class. That way you can reuse the toString method you defined in your square class.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Shavnir posted:

What do you mean visible to each other? Do you want to see them listed next to each other or something?

I think he wants them to be automatically imported when he creates a new class.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Mustach posted:

Yes, let's teach beginners to stubbornly ignore all non-Sun libraries and tools like parser generators, etc.

There are these things called JARS that you can include in your project. If your IDE is using some proprietary JARS that aren't being copied in the project folder, it sucks!

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I don't know what you original question was but I'm pretty sure it could be fixed by a fixed place decimal class. Java also has the BigDecimal class which is part of the standard library and could probably serve your needs. Just keep in mind that working with theses classes is slower than their primitive counterparts (float, double).

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
If you know ahead of time that the item will be altered, why not just send it a temporary copy?

Janitor Prime fucked around with this message at 16:44 on Sep 1, 2009

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
You do know that this is the Java and not the javascript thread right?

Adbot
ADBOT LOVES YOU

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
The = operator is not the same as the == operator. You need to use == in order to compare two numbers.

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