+ 1

Confused by hovercraft!!

I know I am not the only person to be confused by the Hovercraft problem! I am a bit confused by the question. I thought I had it worked out but have I over thought the problem with the code below or just got it completely wrong altogether? public class Hovercraft { public static void main(String[] args) { int cost = 2000000; // this is the cost of each hover craft to make int price = 3000000; // this is the price each hover craft is sold for int insurance = 1000000; // this is paid out each month int unitSold = 2; // this is how many are sold each month int unitIncome = (price - cost); // income per unit sold int monthIncome = (price * unitSold); // how much profit is made each month int monthOutgoing = (cost * unitSold) + insurance; // how much is spent each month if (monthIncome > monthOutgoing) { System.out.println("Profit"); } else if (monthOutgoing > monthIncome) { System.out.println("Loss"); } else { System.out.println("Broke even"); } } }

9th Jan 2020, 5:36 PM
Mark McGimpsey
Mark McGimpsey - avatar
5 ответов
+ 1
You're welcome.
20th Jan 2020, 6:30 PM
Mihai Apostol
Mihai Apostol - avatar
9th Jan 2020, 5:49 PM
Mihai Apostol
Mihai Apostol - avatar
+ 1
Mark McGimpsey Your approach was correct, you were a little off at some point. But you were on the right track. I liked that you used comments on your code, first it is helpfull to you but also when asking for help. I linked first that post because I was thinking you have a similar problem. Below I attached your code with corrections and comments. If you have any questions feel free to ask. It should pass all the tests. Good luck on your plans and life. https://code.sololearn.com/cqx4An1haIS7/?ref=app
19th Jan 2020, 7:10 PM
Mihai Apostol
Mihai Apostol - avatar
+ 1
thank you very much. that clears it up a bit and i can see i should have used the scanner for user input. thank you again for the time youve taken.
20th Jan 2020, 6:29 PM
Mark McGimpsey
Mark McGimpsey - avatar
0
Mihai thank you for your response but I don't really understand anymore. That is a link to how someone else has done it. I am still not sure if I am wrong because as I understand it I still get the right output. Have I got it completely wrong or am I just overthinking it? Is there only one way to do it and is that it?
19th Jan 2020, 3:28 PM
Mark McGimpsey
Mark McGimpsey - avatar