jasimp 427 Senior Poster Featured Poster

You just have to carefully follow the method calls. When fun(5) is called it prints out 5, then subtracts 1 from 5 and then calls fun(4). Now it prints out 4 and calls fun(3). It does this until it reaches zero. Once it stops calling fun(x) you have to backtrack through the method calls for the second print statement.

The most recent method call was fun(1), where the value of X now equals zero so it prints out returning 0. The second most recent call was fun(2) so it prints out returning 1. And so on. Each method is never completed until you backtrack through all the other ones.

It's kind of hard to explain, try drawing out the method calls to make it easier to understand. It is basically the fundamental property of recursion.

jasimp 427 Senior Poster Featured Poster

If you are going to provide code to be used as a learning tool it needs to be commented well.

jasimp 427 Senior Poster Featured Poster

After being gone for so long the news stories appear to be more interesting than they were when I was last here. I'll try reading them everyday and let you know if I feel more current than I did without them :)

jasimp 427 Senior Poster Featured Poster
jasimp 427 Senior Poster Featured Poster

Just for future reference, please make thread titles more specific, so I know which ones to avoid.

jasimp 427 Senior Poster Featured Poster

Make your own.

jasimp 427 Senior Poster Featured Poster

Write out what the program needs to be able to do, step by step.

Think and realize what needs to be in separate classes and figure out the class structure. This will help break down the program into smaller more manageable bits.

Write some pseudo code for each class. Then write the actual code.

Test endlessly for logic errors, stupid user errors, et cetera.

Of course you don't have to follow this, it's not even what I do (I hate pseudo code ;) But it's a good starting point for beginners.

Also, the Java API is your best friend (or try out the Java Docs by Example Once you have written some code, if you come across any problems that you are having trouble with come back and ask a specific question.

jasimp 427 Senior Poster Featured Poster

So AD, I finally found your secret identity... in the attached screenshot ;)

jasimp 427 Senior Poster Featured Poster

NicAx64 your "formatting" is ridiculous.

jasimp 427 Senior Poster Featured Poster

No

jasimp 427 Senior Poster Featured Poster

Yeah i had an infinate loop in my java program i wrote which which screwed up and wrote a text file into every folder on my filesystem. Fun times.

hahaha

jasimp 427 Senior Poster Featured Poster

It's quite old.

jasimp 427 Senior Poster Featured Poster

The way your totalCost() method is now makes sense except for

double finalCost = stickerPrice - (1 - stickerPrice*discount);//why are you subtracting from 1??

If you are going to be multiplying by .01, or any decimal, you need to make your variable a double, not an int, otherwise it just rounds up. So change discount to a double.


And no, I don't see the purpose in having discount() return anything. I think set and get methods are all you need for discount.

jasimp 427 Senior Poster Featured Poster

Sorry about all the commenting in the code, but I find it helps a lot.

A lot of commenting is a good thing, its a great habit to have, because it helps others read your code and makes it more organized when you have very large projects, comment away.

I'm not exactly sure how I'd go about to calculate the final cost or how to change the availability.

final cost is just stickerPrice - discount right? To change the availability you already have a setAvailability() method, so just call that method, it's either going to be setAvailability(true); or setAvailability(false);

Also, an error that I'm getting is that the JOptionPane isn't being found.

That is because you have to tell the JOptionPane what Swing Component is its parent, in your case, just set it to null JOptionPane.showMessageDialog(null, "The car is used."); Two more things, I was looking at your discount() method, honestly I'm not sure what you're doing there, the math doesn't seem logical. Second thing, in your used() method, a car can be used and still have a year of 2009.

jasimp 427 Senior Poster Featured Poster
jasimp 427 Senior Poster Featured Poster

So what is your theory?

That size defeats us.

jasimp 427 Senior Poster Featured Poster

Like I said, instantiating is just creating an object, here is the link from the Java tutorials Sun provides.

jasimp 427 Senior Poster Featured Poster

Yes you can do this as a console program. An idea would be to have a HashMap, where the key's are each letter from the alphabet, and the corresponding value is the String you want to replace it with. You could read in a text file to populate the HashMap (or hard-code it yourself, the text file is the better option though). Then when you take the input, say "blue", you would read each char into an array, and then simply loop through the array, matching the array value with the HashMap key.

jasimp 427 Senior Poster Featured Poster

Instantiate, basically, means to create an object. Right now you are trying to call a method, on the object br, yet you haven't created this object yet. Are you taking a class, or learning on your own? This is basic stuff that is generally taught before you start creating your own classes.

jasimp 427 Senior Poster Featured Poster

I really feel like sweat dropping at my stupidity.

Stupid me for not testing more than once, I was kind of in a rush to get to bed :$

Nice job figuring it out yourself, and thank you for marking this thread as solved.

jasimp 427 Senior Poster Featured Poster

You never instantiate an object with the name br.

jasimp 427 Senior Poster Featured Poster

despite two errors I am experiencing.

What errors? I don't see any in the code. However you do declare DISCOUNT_ONE DISCOUNT_TWO and DISCOUNT_THREE in your main method, which you don't need because they are used in declared in calculatePrice().

When I compile and run the program discountedPrice and discountPercent are miscalculated.

Say something costs 15 dollars. The way your code is written it would be eligible for the DISCOUNT_THREE percentage, so each item would get 2.25 dollars off. Now each item costs 12.75 dollars. If I bought ten of them the total price would be 127.50 dollars. That is the way your code works. I ran those numbers into your program and got this output Original Price: 15.0 Discount Percent: 15.0 Discounted Price: 2.25 Quantity: 10 Total Price: 127.5 If those numbers aren't what you think they should be, how do you think the discountPercent and discountPrice and totalPrice should be calculated?

jasimp 427 Senior Poster Featured Poster

the only people i see regularly in the list are:
[attach]12639[/attach]

I see myself in there!!! ;)

jasimp 427 Senior Poster Featured Poster

Being familiar with the Java API, available online here, is imperative if you plan to program any further in Java. Another fantastic resource is http://www.javadocexamples.com. This has most of the Java API with example code. For instance, if you had looked through that site, you would have found the Random class, with example code, here. Good luck.

jasimp 427 Senior Poster Featured Poster

If you are using the printStringArray() in the class it is declared in then it would be printStringArray(reader); . Otherwise you would have to know what class it is declared in, and then create an object of that type and use it that way.

public static void main(String[] args){
     ArrayPrinter printer = new ArrayPrinter(); //printStringArray method declared in this class
     String[] reader = new String[5];
     printer.printStringArray(reader);
jasimp 427 Senior Poster Featured Poster

You can't declare a method inside another method, or a constructor. So you need to move your entire setPoint() out of the Card constructor.

jasimp 427 Senior Poster Featured Poster

I should also note that no variables are allowed besides the two that the user inputs as the integer, and digit to be checked for

I think this requires the use of at least one more variable. I would read the integer in as a string, create an array of all it's char's and then compare each one to the digit.

jasimp 427 Senior Poster Featured Poster

"how about the illegal start of expression?"

Sorry I wasn't clear. When I said "it appears you are trying to declare a method within your constructor" I was referring to your illegal start error.

jasimp 427 Senior Poster Featured Poster

Do you have to write this method yourself? If not, I'm 99% sure its not part of the standard API. If you just have to use the method some common sense is helpful. Method's are named so that you don't really need to know how they work to use them. printStringArray most likely takes a String[] parameter, and prints it out.

jasimp 427 Senior Poster Featured Poster

Please wrap your code in code tags, simply highlight your code and click the code button at the top of the reply box. From the unformatted code it appears you are trying to declare a method within your constructor, you might have delimiter, aka bracks... { }, problems as well. Make sure each open { has a close }