I have a program to write and keep getting syntax error but can't figure out what is the error, can somehelp me out here, any kind of help with it will be greatly appreciated. here is the program and what I have so far.

this is the program:
Write a program which, when run, works as follows:
Hi, whats your name ? Mr.Best
Welcome to our show, Mr Best
How old are you? 52
Hmmmm, you don’t look a day over 47
Tell me, Mr.Best , how many cars do you own? 0
Wow, come on now Mr Best, you are 52 and do not own a car! SMH!!
Note, if the user is less than 22 years then they should not be allowed to continue the game and should be forced to exit the game.

If the user owns a car or own multiple cars then the rest of the program will
work as follows:
Mr Best, what is the brand and model of your car? Nissan B14
Nissan B14 is a great choice for a car.
Mr. Best have a bless day. Good Bye!!

here is what I have so far.
Scanner read = new Scanner (System.in);

        String user_name, model_of_car, cars, owner;
        int age, fake_age;

        System.out.println("Hi what is your name");
        user_name = read.nextLine();

        System.out.println("Welcome to our show");

        System.out.println("How old are you");
        age = read.nextInt();

        fake_age = age -3;

        System.out.println("Hmmm you dont't look a day over " + fake_age);

        System.out.println("Tell me Mr Tan, how many cars do you own");

        if(user_name<22) - am getting an error at this line, can't seem to figure what is the error
        {

            System.out.println("Print out the user exit the game");
        }


        else if (owner own multiple cars)- getting an error and can't figure out the error.
        {

           System.out.println("print the user should continue as follows");

        }

        I am onto the neste if. if, else if statement
        as i said before anyhelp would be appreciated. thank u very much. and when I run the program this what I am getting:
        Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - bad operand types for binary operator '<'
  first type:  java.lang.String
  second type: int
    at fakename.Fakename.main(Fakename.java:33)
Java Result: 1
BUILD SUCCESSFUL (to

if(user_name<22)

user_name is a String so you can't compare it to a number like that. Maybe you ahould be comparing the user's age, not their name?

sure! @JamesCherrill
user_name is an String ("anName"), can u compare an Name with an Number??? i can say... if name "Divinity" is less than 22... it not have logic! ... so maybe obtain problems in the future with the variable "cars" configured by String ... however it will be an int (integer-number) ... because u need later compare the cars with numbers, 0, 1 or more.
regards.

You can't compare a string with an integer.It's like saying are apples less than 10? because apples does not have any value. You should compare 22 with the user age.

Also on line 16 you should be outputting the name of what you entered from the beginning right? So it should be

System.out.println("Tell me " + user_name + " ,how many cars do you own");
int numberOfCars = read.nextInt();

And since its asking for how many cars the user owns then it should read an integer

This article has been dead for over six months. Start a new discussion instead.