Results 1 to 7 of 7
  1. #1
    JMONEY15 is offline Member
    Join Date
    Jun 2016
    Location
    Los Angeles
    Posts
    5
    Rep Power
    0

    Default Need Help?I do not know how to even start it. I am new to java programing

    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.
    Last edited by JMONEY15; 06-05-2016 at 05:44 AM.

  2. #2
    JMONEY15 is offline Member
    Join Date
    Jun 2016
    Location
    Los Angeles
    Posts
    5
    Rep Power
    0

    Default Re: Need Help?I do not know how to even start it. I am new to java programing

    this is what i have so far
    Java Code:
    import java.util.Scanner;
    
    public class Cars {
    
         public static void main (String[] args) {
    
                Scanner input = new Scanner(System.in);
    
                System.out.println("Enter the price of car one: ");
                int carOnePrice = input.nextInt();
    
                System.out.println("Enter the price of car two: ");
                int carTwoPrice = input.nextInt();
    
                System.out.println("Enter the price of gas in your area: ");
                double gasPrice = input.nextDouble();
    
                System.out.println ("What is the average mpg of car one? ");
                int carOneMpg = input.nextInt();
    
                System.out.println ("What is the average mpg of car two? " );
                int carTwoMpg = input.nextInt();
    
                System.out.println("Give me an amount of miles total you think you will drive in this car: ");
                int milesDriven = input.nextInt();
    
                double gasCostCarOne = (milesDriven / carOneMpg) * gasPrice;
                double totalCostCarOne = gasCostCarOne + carOnePrice;
    
                double gasCostCarTwo = (milesDriven / carTwoMpg) * gasPrice;
                double totalCostCarTwo = gasCostCarTwo + carTwoPrice;
    
                if (totalCostCarOne < totalCostCarTwo) {
    
                        System.out.println("Car One will, in total, cost less than car two. Buy it.");
                }
    
                else {
    
                        System.out.println("Car two will, in total, cost less than car one. Buy it.");
                }
          }
    }
    Last edited by JosAH; 06-05-2016 at 06:39 AM. Reason: added [code] .. [/code] tags

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Need Help?I do not know how to even start it. I am new to java programing

    I added those code tags for you, it improves readability; what is your question? Does your code compile? Does it run correctly?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    JMONEY15 is offline Member
    Join Date
    Jun 2016
    Location
    Los Angeles
    Posts
    5
    Rep Power
    0

    Default Re: Need Help?I do not know how to even start it. I am new to java programing

    Quote Originally Posted by JosAH View Post
    I added those code tags for you, it improves readability; what is your question? Does your code compile? Does it run correctly?

    kind regards,

    Jos
    I haven't added the estimated resale value after 5 years. That is the only thing that i haven't added to the code but i was wondering if my program follows the directions because my professor is very picky.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Need Help?I do not know how to even start it. I am new to java programing

    Well, I didn't really scrutinize the code, but it looks ok to me: all the code has to do is ask for the input, do some calculations and determine which car is cheapest. Add those resale values and you're done.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    JMONEY15 is offline Member
    Join Date
    Jun 2016
    Location
    Los Angeles
    Posts
    5
    Rep Power
    0

    Default Re: Need Help?I do not know how to even start it. I am new to java programing

    Thank you i will. i made the code so the user can know by the user entering all the values. that is why I'm stuck on the resale. for example how can i make the code work so that whatever the users input i can also give them the resale value of the cars.
    Last edited by JMONEY15; 06-05-2016 at 07:28 AM.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Need Help?I do not know how to even start it. I am new to java programing

    The program itself doesn't know the resale value; it's a user supplied value. It all the costs minus the resale value for car A is lower than for car B, car A would be the best choice.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Java programing environment
    By alex30 in forum New To Java
    Replies: 3
    Last Post: 12-25-2011, 12:46 AM
  2. java programing contest
    By ZVY-TRAG in forum Java Software
    Replies: 4
    Last Post: 08-17-2011, 04:44 AM
  3. Regarding OS for Java Programing
    By Sanjeeva in forum Advanced Java
    Replies: 3
    Last Post: 01-19-2011, 06:57 PM
  4. java programing homework help!
    By mxrider in forum New To Java
    Replies: 17
    Last Post: 02-09-2010, 03:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •