• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help a person decide whether to buy a hybrid car

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 186
1
Netbeans IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28245
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 186
1
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 186
1
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 79278
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5466
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Saloon Keeper
Posts: 10750
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic