Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help a person decide whether to buy a hybrid car  RSS feed

 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the directions: Write a program that as helps a person decide whether to buy a hybrid car. Your program's inputs should be: *the cost of a new car *estimated miles driven per year *the estimated gas prices *the efficiency in miles per gallon *the estimated resale value after 5 years compute the total cost of owning the car for 5 years. (for simplicity, we will not take the cost of financing to account). Obtain realistic prices for a new and used hybrid and a comparable car from the web. Run the program twice, using today's gas price and 15,000 miles per year.
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Castellanos wrote:Here are the directions: . . .


Can you show the work you have done so far to write the program. I will be more than happy to help if you show us what you have done so far.
 
Paul Clapham
Sheriff
Posts: 22472
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Josh, welcome to the Ranch!

So, what kind of help are you looking for? Bear in mind that we aren't a code mill and we don't do people's homework. But beyond that there are people here who would like to help you. What have you done so far?

(See what I mean? 10 seconds before I post and you already have a volunteer.)
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that is were i am stuck i have no idea how to even start the program
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Hi Josh, welcome to the Ranch!

. . .

(See what I mean? 10 seconds before I post and you already have a volunteer.)



I just need help starting it because i am at a impasse on how to start it
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Castellanos wrote:that is were i am stuck i have no idea how to even start the program


Josh, when you write a program, you are often trying to solve a problem. What I typically do is break the problem up into pieces.

Write a program that as helps a person decide whether to buy a hybrid car. Your program's inputs should be: *the cost of a new car *estimated miles driven per year *the estimated gas prices *the efficiency in miles per gallon *the estimated resale value after 5 years compute the total cost of owning the car for 5 years. (for simplicity, we will not take the cost of financing to account). Obtain realistic prices for a new and used hybrid and a comparable car from the web. Run the program twice, using today's gas price and 15,000 miles per year.

So break it up:

1. Program inputs should be cost of a new car, estimated miles driven per year, estimated gas prices, mpg for car, estimated retail value after 5 years.

So have you ever heard of a Switch-Case structure before? It sounds like the program is asking for some kind of menu in which the user selects one of those 5 options so let's say for instance I select #1, the program would give me output to the console that says "What is the cost of the new car?", if I press #2, the program would prompt the user at the console: "What are the estimated number of miles driven per year" and so on.

For a decent console UI, I would use a Switch-Case structure. Read up on it if you are unfamiliar with it here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

Let me know what you think.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naziru Gelajo wrote:. . .
Josh, when you write a program, you are often trying to solve a problem. What I typically do is break the problem up into pieces.

. . .

So break it up:

1. Program inputs should be cost of a new car, estimated miles driven per year, estimated gas prices, mpg for car, estimated retail value after 5 years.

. . .

Let me know what you think.




Thank you, you summed it up for me perfectly. I have never heard of Switch-Case. Ill use this information that you provided to me and I'm going to start the program
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Josh Castellanos wrote:. . .
Thank you, you summed it up for me perfectly. . . ./quote]

Sure no problem, let me know if you need further help.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


this is what i came up with is it good. i know I'm missing the resale after five years but am i on the right track.
 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 55681
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again.
Please don't quote the whole of eveybody's posts; that simoply makes the thread longer and longer. I have removed most of the unnecessary quotes.
I would say you should create a Car class with mileage, etc., as its fields. It should have getCost methods for different kinds. What you have is not object‑oriented programming, I am afraid, because you don't have any Car objects.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should also get in the habit of not writing your code in main(). The main() method should launch your app and that's all. See Main is a Pain.
 
Piet Souris
Rancher
Posts: 1979
67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt if I would make a Car class. The questions are not specific to a special brand of Car.
(or even to a car; only the wording of the questions might be).

I think all that is needed is a method that takes these parameters and delivers the
total cost of ownership, eased by the fact that cost of finance is to be left out.
And this method must be outside of main().

 
Josh Castellanos
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have corrected my code to fit the directions. I did not specifically chose a hybrid this is a averaged number of what a hybrid cost today and what it cost in 2014.


 
Carey Brown
Bartender
Posts: 2990
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constants should be in all upper-case letters. Constants should be declared and initialized inside the class and outside of any method.

Local final variables are not constants. Unlike the value of a constant, the value of a final variable is not necessarily known at compile time. It is considered good practice to represent final constants in all uppercase, using underscore to separate words, and local finals using camel-case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!