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

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

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

Alright, lets go through what you need to output step by step.

You want to output the original price of the item, which works, although I would change

public static void calculatePrice(double amount, int quantity)

to

public static void calculatePrice(double price, int quantity)

This way it is easier to follow all of your variables.

Next you want to output the discount percent, which you calculated by dividing the price by 100.

discountPercent = (amount / 100);

So if someone spends 100 or more, they get a 100% discount? I think you meant to use the three variables you declared in your main method DISCOUNT_ONE DISCOUNT_TWO and DISCOUNT_THREE and the switch statements inside your main method to calculate the discount. As your program is now the output comes before the switch statements, so they are useless. You should move those into your calculatePrice() method and change price to discount price like so...

case 1: if(price < 5.00);
	discountPrice = price * DISCOUNT_ONE;
	break;
case 2: if(price < 10.00);
	discountPrice = price * DISCOUNT_TWO;
	break;
case 3: if(price > 10.00);
	discountPrice = price * DISCOUNT_THREE;
	break;

Next time follow the same basic steps I did here, go through what your program needs to do, break it down into simple steps, and follow your code, if you had gone through it line by line, command by command, you would have seen these pretty simple errors. There might still be some problems once you make those changes, from …

jasimp 427 Senior Poster Featured Poster

EDIT: Well, this is odd. I am able to view my applet within an IDE but not through a browser (Firefox 3.5). Any ideas to why this is?

Not really lol. I never had to integrate them with webpages, I just had to make some for a class once. I'm sure someone else around here will know.

jasimp 427 Senior Poster Featured Poster

Read the Java tutorial on applets, here. You are missing a key method every applet needs.

jasimp 427 Senior Poster Featured Poster

The caps are unnecessary, don't use them.

Secondly, there is nothing wrong with the code, it works perfectly, what you have is a logic error. The problem is in your line

System.out.println(a);

You need to either override Area's toString() method, which it inherits from Object, or you need to right your own print method for Area.

After your write your new method for Area your pintln statement should look like this

System.out.println(a.printMethod());
jasimp 427 Senior Poster Featured Poster

You need to add ItemListener to your combo-box. The sun tutorial is brilliant, look here :

http://http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html

I hope that helps!

EDIT: lol James Cherrill, you just beat me to it! Same tutorial as well, great minds...

Your link doesn't work, you have an extra http://

Here is a working version of your link :)

majestic0110 commented: lol thanks for spotting that, silly me ! +5
jasimp 427 Senior Poster Featured Poster

If you change the default number of posts per thread in your control panel you can view it as one page. This can be a temp fix for you while Dani is sick.

jasimp 427 Senior Poster Featured Poster

I tried in both IE7 and FF 3.5 Beta 4. Yeah I can get to the window, it just won't upload.

jasimp 427 Senior Poster Featured Poster

When I click upload the upload manager just becomes a blank white screen.

jasimp 427 Senior Poster Featured Poster

In addition to what James has said; if you want to be able handle more than one client you will need to create a thread for each client that connects.

jasimp 427 Senior Poster Featured Poster

When I made a chat application I had the same problem. If you had googled a little harder you could have found this solution.

//incoming is the JTextField that displays the conversation
//doc is a previously initialized Document object. 
doc = incoming.getDocument();
incoming.setCaretPosition(doc.getLength()-1);
jasimp 427 Senior Poster Featured Poster

Do you want a cookie or something?

Sure. I love cookies :)


@Serkan
Just give up the argument. Cheating is bad. It is as simple as that. Look at the definition of cheat, nothing good is said about it. You should have let the cheating thing die, now it's a zombie that wants to eat its master(you).

jasimp 427 Senior Poster Featured Poster

I finally got around to linking a website to my posts, but it's not showing up. I typed in the website URL in the "Home Page URL" box in my Control Panel, but I'm not seeing it on my posts. Did I do something wrong?

I didn't know it was supposed to appear on posts. If I click on your username, I have the option to visit your homepage.

jasimp 427 Senior Poster Featured Poster
boolean display = A.B(inputInfo);

The return statement you used is legal. You can return false, true, or a boolean variable when using a boolean method. When you call A.B() that line of code becomes (basically anyways) the data type you are returning. That is why if you have a method that returns a String you can say

String testString = Class.returnMethod(someVariable)

As long as returnMethod() returns a String, the above code will work. The same concept applies to your situation.

jasimp 427 Senior Poster Featured Poster

I know this is a beginner question but it is something that I have never had to do before. Is this the correct way to import the other classes?

Why would you do this in your GeometricObject class? Just create a driver class, here's the one I made.

public class Tester {
public static void main(String[] args) {
	Triangle tri = new Triangle(56,56,56);
	System.out.println(tri.perimeter());
	Isosceles iso = new Isosceles(56,56);
	System.out.println(iso.perimeter());

}

}

Creating a driver class just tests code from other classes you have built. Your GeometricObject class is an abstract class and has no need to import the other classes because it never uses them. I'm pretty sure that if you keep your Java files in the same folder, say "/Java Code/Geometric" when you compile them the compiler will find all the classes it needs.

Grn Xtrm commented: Thanks for walking me through the process. +1
jasimp 427 Senior Poster Featured Poster

If all that code is one Java file than that could be the problem. I separated each class GeometricShape, Triangle, Isosceles, Equilateral, into it's own file and had no trouble running a driver class creating each type of triangle.

jasimp 427 Senior Poster Featured Poster

hi
how i can do this by StringTokenizer

Is there a more easy efficient method?

Easy is relative, what might be easier for some could be really hard for you.
Google StringTokenizer examples, read the API and then start writing some code. When you have shown some effort come back, post your code and ask a specific question.

This tutorial should get you started.

jasimp 427 Senior Poster Featured Poster

Amazing. Visiting the Geeks' Lounge is like sitting in a room full of children.

Maybe you should lobby to follow up on Rashakil's suggestion, Day Care, but instead of creating a new forum, just rename this one :)

Ancient Dragon commented: Nice suggestion :) +36
jasimp 427 Senior Poster Featured Poster

Why?

I must be too stupid to figure out why you think I don't have a sense of humor? Although your old age of 95 might have something to do with it ;) My post wasn't supposed to be taken seriously anyways; I had been following this little "game" of yours and serkan's for the past few days and found it interesting. I thought the Geeks' Lounge would be a much better forum to comment on it than in the tech forums.

jasimp 427 Senior Poster Featured Poster

Rashakil Fol,
What don't I have a sense of humor about? You should have been more specific.

jasimp 427 Senior Poster Featured Poster

Hope that helps.

It doesn't help because you just threw code at the OP, didn't offer any explanation to what you changed and didn't even show what you fixed. You should point the OP in the right direction instead of thrusting code at them.

jasimp 427 Senior Poster Featured Poster
public Triangle(double s1, double s2, double s3)
	{
		this.side1=s1;
		this.side2=s2;
		this.side3=s3;
	}
	

	
	public Isosceles( double EQside, double otherside)
	{
		super(EQside, otherside); //calls triangle constructor 
	}


	public Equilateral(double side)
	{
		super(side); //calls isosceles constructor. 
	}/

Look at all your constructors. You have one triangle constructor, and it takes three parameters. Then in the Isosceles constructor you call super() with two parameters. You made the same mistake in the Equilateral constructor.

jasimp 427 Senior Poster Featured Poster

Your beautiful hands turn me on...

I'm going to make it so dry for you.

I think your attempt of "[making] [his] existence on this forum a miserable one." isn't working. He seems to be posting more often.

http://www.daniweb.com/forums/post818433-15.html

Rashakil Fol commented: You have no sense of humour. -2
nav33n commented: You do have sense of humour ;) +10
jasimp 427 Senior Poster Featured Poster

i want to see the names for the poster titles, the ones starting from newbie to ... . is there any complete list of them?

This question has been asked so many times before. There is no list because Dani wants it to be a surprise, of sorts.

i also want to know what are the roles of moderators, super mod, staff writer, administrator and so on.

Here is the list of moderators, super mod and administrators, plus the links to the other groups. I'm sure one from each group could tell you their exact responsibilities, if they wish too. But moderators make sure the rules are followed within the forums, super mod has the power to change all sorts of things, the admins don't do anything (just kidding ;) and I think Team Colleagues are past moderators.

jasimp 427 Senior Poster Featured Poster

Please help I am stuck. I am trying to retrieved text from a file named "text.txt" and reversing the contents to another file named "output".

Your code doesn't even attempt to write to a file. It only reads. Try to write to the file and if you're stuck, show us your new code.

jasimp 427 Senior Poster Featured Poster

I personally recommend Head First Java.

jasimp 427 Senior Poster Featured Poster

...it can't be denied that knowing the basics of the language you develop in of prime importance.

It is important, that is why I agree that IDE's should not be used when first learning a language. But my point was certain IDE's can, if you truly want to learn, help you learn common method signatures, what commonly used methods do. They will only help beginners if the user actually types everything out themselves, instead of using code completion, code generation et cetera.

I am pretty sure none of us would want to hire someone who is completely lost without an IDE; after all, it's a Java developer we are looking for and not just a Eclipse/Netbeans/IntelliJ user.

Which is what happens when beginners are incorrectly taught to always use and IDE (which is why they should not use them), instead of using it when they are ready.

jasimp 427 Senior Poster Featured Poster

Using an IDE just because you don't or don't want to remember langauge syntax and API is totally useless,

While I do agree with your post in its entirety I think using certain IDE's, such as Eclipse, can be very useful in learning the API. In Eclipse, whenever you access a method, it gives you a summary of what the method does, as given in the API. This is a great opportunity to really explore the API.

jasimp 427 Senior Poster Featured Poster

Use a suitable tool for creating software. Use free IDE NetBeans.http://www.netbeans.org/downloads/

Uhh... how is this helpful?

I'm sure your book must show you examples of constructors, private methods and their uses. Anyways a private method is a method that can only be used in the containing class. They are generally called support methods because they are used only within the class.

If you do not provide a constructor, Java automatically uses a default constructor, which is a no argument constructor

//default constructor, no argument
public Complex(){
}

// a constructor that takes arguments
public Complex(double one, double two){

}

To go from there I'll need to know exactly what you are having trouble on, besides a vague, "private methods, constructors, and calling different classes."

jasimp 427 Senior Poster Featured Poster

i think before i do anything else, i need some sleep. 4.5 hrs of sleep a night for 2 nights isn't the best idea....

If you're sleeping polyphasically that could be to much sleep :)

jasimp 427 Senior Poster Featured Poster

I have this wierd kink in this program, it keeps telling me that there is a "missing return statement for public static question. i'm kind of new to JAVA and i've tried everything! please can someone help!

"missing return statement" is saying there is a way question() could run without ever coming across a return statement. It's hard to tell where it needs to go in that un-formatted code but seeing as you are using a switch statement you need to have it return something in the default case, or have it return something out of the switch statement. On another note, generally you put the default case at the bottom of all your other cases. It makes sense that way because default is saying, "if none of the other cases work, do this one." How does it know if the other cases work when you put default first?

jasimp 427 Senior Poster Featured Poster

And I want a billion dollars :-/

stephen84s commented: Excellent response +3
jasimp 427 Senior Poster Featured Poster

What have you done on this problem? Show us some effort and maybe you will receive help. Also, try google.

jasimp 427 Senior Poster Featured Poster

P.S. If you post your code in more readable state next time, you get the answer much faster :)

If you notice the OP did try to use code tags, just made a little mistake on the second one.

jasimp 427 Senior Poster Featured Poster

What you need to do is mark the thread as solved, so people don't read the whole thing to realize it has been solved. Just for future (and present) reference. Thanks :)

jasimp 427 Senior Poster Featured Poster

and also just to make sure you aren't running client and server on the same machine are you?

I have never had trouble running a server and client on the same machine before, but I haven't looked through the code here to see if they are doing anything different than I usually do. However in an earlier post the OP posted

it reads information:
"
POST / HTTP/1.1
Connection: close
Keep-Alive: 300
User-Agent: Java/1.6.0_07
Host: localhost:2604
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-type: application/x-www-form-urlencoded
Content-Length: 38

Looking at where it says Host: localhost:2604 led me to believe it is being run on the same machine.

jasimp 427 Senior Poster Featured Poster

I understand what you want to tell. Waiting a valid input file may be a good choice.
But, if I don't want to give that right to the user, I mean user has to enter a valid filename at his first choice,else the program has to be terminated. In my program, the absence of that file corrupts program running,that's too, I regard it as RuntimeException and treat it like that. I am asking what else may be done,because Java books suggest not to use exit statement in exceptions.

Peter already said what to do. He said do not exit the program, provide a helpful message to the user and then go back "to the point the file name been submitted for new entry".

jasimp 427 Senior Poster Featured Poster

Hello, I need help!!! Very new to programming.
I need a program that will display...

You already have a thread dedicated to this same exact question here, with quite a few responses.

jasimp 427 Senior Poster Featured Poster

Just create a new color using your values. I added the line of code into your try statement.

try
         {
         red = Integer.parseInt(redText.getText());
         green = Integer.parseInt(greenText.getText());
         blue = Integer.parseInt(blueText.getText());
         if(red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0)
        {
          JOptionPane.showMessageDialog(null, "Please enter a number between 0 and 255!");
          redText.setText("0");
          blueText.setText("0");
          greenText.setText("0");
        }
         else
         {
                 //creates a new color using the values inputed by the user
        	 Color colorTest = new Color(red,green,blue);
          color = "" + red + green + blue;
          JOptionPane.showMessageDialog(null, color);
          //sets the color to the one created from user inputted values
          centerPanel.setBackground(colorTest);
         
         }
         
        }
jasimp 427 Senior Poster Featured Poster

Do you have to do it that way? I think a much more interesting way would be to use ColorChooser

jasimp 427 Senior Poster Featured Poster

You never set operationS to value and then you ask if it equals something. You need to set it to a starting value, or a value inputted from the user.

jasimp 427 Senior Poster Featured Poster

Try saving it to a .png instead of a .gif, that should (hopefully) work.

javaAddict commented: I would have never thought of that +3
jasimp 427 Senior Poster Featured Poster

So the part you are having trouble with is the bold section? If it is think about what modulus ( % ) does. It finds the remainder in division. You need the largest whole number that fits, plus the remainder. So, what I would do is create an value that is equal to the remainder

double remainder = (number1 % number2);

That will be your remainder and if you cast number3 to an int

(int) number3

than you have the largest whole number that fits and the remainder.

jasimp 427 Senior Poster Featured Poster

Have you done any programs before this one? You need to declare main() as

public static void main(String[] args){ 
        
}

You never ended your Inventory class, it needs its corresponding bracket. You need to import java.util.* to use Scanner.

You cannot declare a class like

public class Data video disk

It needs to be one word, as in

class DataVideoDisk{

Change the next block of code to actually declare your variables correctly. You cannot declare an int and String on the same line. Don't forget the semi-colons and make sure to actually give name1 a type.

//every line needs work
        name1 String productName;
	int number1 String productNumber;
	int number2 String productStockAmount;
	int number3 String productPrice;
	int amount String stockValue;

The code above is duplicated right below. You can't use While as a class name, think of something else. You cannot use 'x' as multiplication, it has to be '*'. Start fixing those errors and try to learn the Java syntax because most of your errors were syntax errors.

jasimp 427 Senior Poster Featured Poster

Adblock Plus + NoScript