7 Replies - 271 Views - Last Post: 16 February 2019 - 06:38 AM Rate Topic: -----

#1 gunlake2012   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-February 19

Homework help. Dragster Simulation Program

Posted 15 February 2019 - 06:28 PM

I need help with homework.
Heres the assignment: https://pastebin.com/F6dwR0py

I need to create a dragster program. I can finish the rest of the program, I just can't get it to calculate. It returns a 0.0. I am still very new at java so I've been playing around with different ways, This is the closest ive come. Any tips/advice would be awesome. Not looking for answers but help. And please dumb it down for me. I've read the book 100 times. Having a hard time understanding multiple methods/classes. And my book isn't doing a great job explaining it to me. Thanks.
import java.util.Scanner;

public class  Test2 {
    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        Dragster dragster1 = new Dragster();

        System.out.println("What is Driver's Name?: ");
        dragster1.driverName = input.nextLine();
        System.out.println("Enter the color of the car: ");
        dragster1.color = input.nextLine();
        System.out.println("Enter Cars Horsepower: ");
        dragster1.hp = input.nextDouble();
        System.out.println("Enter Car's RPM: ");
        dragster1.rpm = input.nextInt();
        System.out.println("Enter Car weight: ");
        dragster1.weight = input.nextDouble();


        System.out.println(dragster1.acceleration);
        System.out.println(dragster1.getDistance(1320));


    }
}
class Dragster {
    String color;
    String driverName;
    double hp;
    int rpm;
    double weight;
    double wheelDiameter;
    double acceleration;
    double distance;


    double getAcceleration() {

        acceleration = (hp * 169017 ) / ( rpm * weight * wheelDiameter );

        return this.acceleration;
    } //End getAcceleration

    double getDistance(int time) {

        distance = 0.5 * acceleration * time * time;

        return this.distance;
    }


} 


Is This A Good Question/Topic? 0
  • +

Replies To: Homework help. Dragster Simulation Program

#2 gunlake2012   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-February 19

Re: Homework help. Dragster Simulation Program

Posted 15 February 2019 - 07:10 PM

I found where i missed some code. but still getting 0.0 has my displayed result.

import java.util.Scanner;

public class  Main {
    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        Dragster dragster1 = new Dragster();

        System.out.println("What is Driver's Name?: ");
        dragster1.driverName = input.nextLine();
        System.out.println("Enter the color of the car: ");
        dragster1.color = input.nextLine();
        System.out.println("Enter Cars Horsepower: ");
        dragster1.hp = input.nextDouble();
        System.out.println("Enter Car's RPM: ");
        dragster1.rpm = input.nextInt();
        System.out.println("Enter Car weight: ");
        dragster1.weight = input.nextDouble();
        System.out.println("Enter Wheel Diameter");
        dragster1.wheelDiameter = input.nextDouble();


        System.out.println(dragster1.acceleration);
        System.out.println(dragster1.getDistance(1320));



    }
}
class Dragster {
    String color;
    String driverName;
    double hp;
    int rpm;
    double weight;
    double wheelDiameter;
    double acceleration;
    double distance;


    double getAcceleration() {

        acceleration = (hp * 169017 ) / ( rpm * weight * wheelDiameter );

        return this.acceleration;
    } //End getAcceleration

    double getDistance(int time) {

        distance = 0.5 * acceleration * time * time;

        return this.distance;
    }


}


Was This Post Helpful? 0
  • +
  • -

#3 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 762
  • View blog
  • Posts: 5,725
  • Joined: 25-December 13

Re: Homework help. Dragster Simulation Program

Posted 15 February 2019 - 07:57 PM

Can you post the console's contents with the program's output that shows what you are talking about?

What variable has the value of 0.0? Where is that variable assigned a value other than 0.0?
Was This Post Helpful? 0
  • +
  • -

#4 gunlake2012   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-February 19

Re: Homework help. Dragster Simulation Program

Posted 15 February 2019 - 09:15 PM

View PostNormR, on 15 February 2019 - 07:57 PM, said:

Can you post the console's contents with the program's output that shows what you are talking about?

What variable has the value of 0.0? Where is that variable assigned a value other than 0.0?



Then console just out puts
0.0
0.0

Here is what im trying to output.
System.out.println(dragster1.acceleration);
System.out.println(dragster1.getDistance(1320));
Was This Post Helpful? 0
  • +
  • -

#5 chanjul   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 60
  • Joined: 11-September 18

Re: Homework help. Dragster Simulation Program

Posted 16 February 2019 - 12:03 AM

Did you call the method to the main class?
it seems to me that you didn't call the method. that's why it return 0.0

dragster1.getAcceleration()
dragster1.getDistance(1320)

This post has been edited by chanjul: 16 February 2019 - 12:06 AM

Was This Post Helpful? 0
  • +
  • -

#6 gunlake2012   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-February 19

Re: Homework help. Dragster Simulation Program

Posted 16 February 2019 - 12:10 AM

View Postchanjul, on 16 February 2019 - 12:03 AM, said:

Did you call the method to the main class?
it seems to me that you didn't call the method. that's why it return 0.0

dragster1.getAcceleration()
dragster1.getDistance(1320)



Thanks for the reply, Yes i caught that as well. Working now. Thank you.
Was This Post Helpful? 0
  • +
  • -

#7 chanjul   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 60
  • Joined: 11-September 18

Re: Homework help. Dragster Simulation Program

Posted 16 February 2019 - 12:11 AM

glad to hear! your welcome
Was This Post Helpful? 0
  • +
  • -

#8 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 762
  • View blog
  • Posts: 5,725
  • Joined: 25-December 13

Re: Homework help. Dragster Simulation Program

Posted 16 February 2019 - 06:38 AM

Strictly speaking, a get method should not change the contents of a class. The purpose of a get method is to return a value, not to change a value inside of a class. There should be a separate method that does the computations. Or it should be done in the constructor.

Also the class's variables should be private.

This post has been edited by NormR: 16 February 2019 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1