Can someone amazing debug (5 errors) my creation in order to make it run properly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone amazing debug (5 errors) my creation in order to make it run properly?

https://code.sololearn.com/c55tf305tu6p/?ref=app

7th Aug 2017, 11:07 PM
Clément Gillet
Clément Gillet - avatar
9 Answers
+ 2
nextString() is not a method. You're looking for next() OR nextLine(). String also has a capital 's'. Fix: String meansOfPayment = in.nextLine(); Line 16. In the if statement you used a comma instead of a decimal. Line 22. BanContact is not defined. Idk what you were trying to do here. Did you want to check if the user wrote that letter by letter? If so, it should be in quotes since it's a String. Also, use .equals() for comparing strings. Fix: if(meansOfPayment. equals("Bancontact")){
7th Aug 2017, 11:57 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
Oh yeah that was it!!! Cheers
8th Aug 2017, 6:27 PM
Clément Gillet
Clément Gillet - avatar
+ 1
,5 in your of statement doesn't make sense
7th Aug 2017, 11:27 PM
James Cooke
+ 1
I may be rusty but does string need to be capitalised as it's a class?
7th Aug 2017, 11:28 PM
James Cooke
+ 1
import java.util.Scanner; /* *input your age *input your height *Cash or Bancontact */ public class exercise5{ public static void main(String[] args) { System.out.println("You are here at the Amusement park sameur. If you comply to all the allowance criterias, you are welcome! "); Scanner in= new Scanner(System.in); int age = in.nextInt(); double height = in.nextDouble(); in.nextLine(); String meansOfPayment = in.nextLine(); if (height > 1.5d && age > 12) { System.out.println("You're welcome, enjoy your stay"); } else { System.out.println("See you another time"); } if(meansOfPayment.equals("Bancontact")){ System.out.println("Insert your card"); } else { System.out.println("Take your notes out! "); } } }
8th Aug 2017, 1:20 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
meansOfPayment.equals("Bancontact") is a String comparison. meansOfPayment must be an exact match including case. So the String entered by the user on this line: String meansOfPayment = in.nextLine(); must be Bancontact exactly or the else statement is ran.
8th Aug 2017, 7:06 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Did you add the extra in.nextLine() before String meansOfPayment = in.nextLine() This is needed to get the left over newline/return character from the in.nextDouble() before it. If not, then it will just catch those characters and will not get the Bancontact that the user enters and will not be equal to it at the if statement. See the code I posted earlier.
8th Aug 2017, 4:09 PM
ChaoticDawg
ChaoticDawg - avatar
0
Thank you so much guys for your contribution, it now, not only works perfectly, but I learned some basic stuff idk! CHEERS! But I still have a little question: if(meansOfPayment.equals("Bancontact")){ System.out.println("Bancontact ? Insert your card!"); } else { System.out.println("Cash? Take your notes out! "); } This never prints Bancontact? Insert your card! Do you know why?
8th Aug 2017, 6:31 AM
Clément Gillet
Clément Gillet - avatar
0
But I write exactly Bancontact and it still outputs cash...
8th Aug 2017, 12:15 PM
Clément Gillet
Clément Gillet - avatar