Java code problems | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Java code problems

https://code.sololearn.com/cEEYRbnnBdCv/?ref=app It must output a price if you input correct model but it doesn't. Do you know where problem is? Don't forget to give me a questions if there is any.

21st Sep 2018, 1:05 PM
Oleg Storm
Oleg Storm - avatar
5 Answers
+ 3
Oleg Storm The main problem with your code is that you are using '==' operator to compare the user input with carModel when you should be using '.equals()' function to compare them. To quote GeeksforGeeks - "== checks if both objects point to the same memory location whereas .equals() evaluates to the comparison of values in the objects." https://www.geeksforgeeks.org/difference-equals-method-java/ If you want your code to print the price of the car if the user entered the correct car model then you need to replace "System.out.println(car.CarModel(model));" with "System.out.println(car.Price());" This should get back on track. Let me know either way.
21st Sep 2018, 5:02 PM
ODLNT
ODLNT - avatar
+ 2
I really didn't know what this (==) means till now🤤, it was so helpful! Thanks a lot for your answer, ODLNT😄.
21st Sep 2018, 6:12 PM
Oleg Storm
Oleg Storm - avatar
+ 1
hi
23rd Sep 2018, 12:29 PM
Ihtsham Ihtsham
0
https://code.sololearn.com/cEEYRbnnBdCv/?ref=app My ultimate thanks to you, guys😊
21st Sep 2018, 6:46 PM
Oleg Storm
Oleg Storm - avatar
0
hi
23rd Sep 2018, 12:29 PM
Ihtsham Ihtsham