+ 1
Can someone amazing debug (5 errors) my creation in order to make it run properly?
9 Respostas
+ 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")){
+ 2
Oh yeah that was it!!! Cheers
+ 1
,5 in your of statement doesn't make sense
+ 1
I may be rusty but does string need to be capitalised as it's a class?
+ 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! ");
}
}
}
+ 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.
+ 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.
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?
0
But I write exactly Bancontact and it still outputs cash...