The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Code bugs

There are a few things wrong with your code:
1) You do not use quotes unless your are creating a String (like raizalnapi said). Although you are, in theory, attempting to create a String, you are just creating the String Object in your parameters. So, instead of this:

you must return a double. I do not know if priceChild and/or priceAdult are doubles or not, you did not specify in your question.

3) You should never compare String with the double equals (==). Really, the only thing you want to compare with the double equals is number types. Instead, for Strings and other Objects, you want to use the .equals() method. For Strings, there are two useful .equals() methods. The first is the .equals(String) method that returns a boolean if the two Strings have the same value (case sensitive). The second is the .equalsIgnoreCase(String) method that returns a boolean if the two String have the same value (not case sensitive).
So instead of:

elseif(showPrice =="Adult")

You would want to say:

elseif(showPrice.equals("Adult"))

These are the things wrong with your code based on what you have provided. There are clearly large chunks of your code that you havent provided, and without providing us with those, we really cant help you out too much.

Re: Code bugs

Originally Posted by aussiemcgr

There are a few things wrong with your code:
1) You do not use quotes unless your are creating a String (like raizalnapi said). Although you are, in theory, attempting to create a String, you are just creating the String Object in your parameters. So, instead of this:

you must return a double. I do not know if priceChild and/or priceAdult are doubles or not, you did not specify in your question.

3) You should never compare String with the double equals (==). Really, the only thing you want to compare with the double equals is number types. Instead, for Strings and other Objects, you want to use the .equals() method. For Strings, there are two useful .equals() methods. The first is the .equals(String) method that returns a boolean if the two Strings have the same value (case sensitive). The second is the .equalsIgnoreCase(String) method that returns a boolean if the two String have the same value (not case sensitive).
So instead of:

elseif(showPrice =="Adult")

You would want to say:

elseif(showPrice.equals("Adult"))

These are the things wrong with your code based on what you have provided. There are clearly large chunks of your code that you havent provided, and without providing us with those, we really cant help you out too much.

I have created two classes, TicketMachine and User. The TicketMachine is supposed to print a ticket with adult tickets and child tickets, amount of money inserted (method), total income, balance etc. The User class is a user-friendly class with options to buy tickets and adjust ticketprices. Her is the java source code for the two classes: