Jump to content

Beginner's Java Programming Help!

I am back again...! With same question..

 

I am still a beginner in Java Programming...& I am not asking answers for my homework..

 

**Just want to know how to input a string[word] as an answer...which is assigned to a number.**

I am creating a car comparing game.....

1. after running the program, in the terminal window...It should ask U to type the name of the car...then 2nd car

2.It will compare it..

3.Then print the name of the car...

 

Please help!

 

post-79918-0-83919900-1417973559.jpg

Link to comment
https://linustechtips.com/topic/265653-beginners-java-programming-help/
Share on other sites

Link to post
Share on other sites

1. after running the program, in the terminal window...It should ask U to type the name of the car...then 2nd car


1) First, if you are getting the names of the cars, then the data type shouldn't be Double. Double is used for a numeric value with decimals. The data type you will want is String. So car1 and car2 should be String. Then, when you are getting the information from the scanner, you will use Mp.nextLine(). This will get the name, with spaces, of the car


 


2.It will compare it..


2) To compare it the cars would have to have a numeric value to them, so if you are getting the names of the cars, then you will have to assign the value of what each car is. What you could do is get the names of the cars, then either use a case structure or if statements to then set values for what the first car is, or the second car. For example, if the first car entered is the Skyline, then give an integer a value of 8, then if the second car is the Porsche, give a second integer a value of 7. Then, compare these two values, and print which is better than which.


 


3.Then print the name of the car...


3) Your print statement is fine, the if statement should work to print which is better.


 


These are just my suggestions, based on what you have said you were looking for.


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×