-2

I am creating a program that will show user how many feet they have travel while driving if they were texting.

So far this is what I got, If the user is driving at 60 MPH, one second of distraction will travel 88ft. If the user is driving at 20MPH, one second of distraction will travel 29ft. ETC.

The problem that I am having trouble figuring out is that if I increment the seconds on this method c.SetHourstoSeconds(1). My program starts dividing, instead of multiplying. I have created new methods but so far I am completely lossed of how to make it work. Thanks in advance.

  public class App {

 public App() {
    //  TODO Auto-generated constructor stub
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Conversions c = new Conversions();



    c.SetMilestoFeet(60);

    c.SetHourstoSeconds(1);


    System.out.println("Total feet travel " + c.Total() + "ft");
   }
  }

public class Conversions {

static int Milestofeet =0;
static int MinutestoSeconds =0;

public Conversions() {

}



public static void SetMilestoFeet(int x)
{

    Milestofeet = x * 5280;




}

public static void SetHourstoSeconds(int hr)
{
    int hourstoMinutes = hr * 60;
     MinutestoSeconds = hourstoMinutes * 60;

        System.out.println("***********" + hr);


}

public static int Sec()
{

    return MinutestoSeconds;
}

public static int Feet()
{

    return Milestofeet;
}


public int  Total()
{
    System.out.print(Milestofeet + "   ___" + MinutestoSeconds + "______=" );

    return (Feet()/Sec());

}

}

user2984143
  • 85
  • 1
  • 11
  • 2
    Please learn and follow Java coding standards. They aren't the same as C#. – duffymo Aug 25 '16 at 18:34
  • "The problem that I am having trouble figuring out is that if I increment the seconds on this method" --- It is not clear what you mean – bradimus Aug 25 '16 at 18:38
  • *"My program starts dividing"* Because you *are* dividing: `Feet()/Sec()` – Andreas Aug 25 '16 at 18:42
  • Sorry for the confusion... What I want to solved is that if a user is driving at 60 MPH and he gets distracted for 2 seconds(or more), then the distance travel will be 176ft, instead 44ft. – user2984143 Aug 25 '16 at 18:44
  • I know I am dividing... But I am getting the feet right. When I input 2 seconds, I should be getting 176ft instead 44ft. – user2984143 Aug 25 '16 at 18:47

1 Answers1

2

You're making this much too hard:

/**
 * Calculate distance traveled per second of distraction
 * User: mduffy
 * Date: 8/25/2016
 * Time: 2:40 PM
 * @link http://stackoverflow.com/questions/39152475/feet-to-distractionSeconds-cant-increment-distractionSeconds-java
 */
public class DistractionDistanceCalculator {

    public static final int FEET_PER_MILE = 5280;
    public static final int SECONDS_PER_HOUR = 3600;

    public static void main(String[] args) {
        double mph = (args.length > 0) ? Double.parseDouble(args[0]) : 60.0;
        double distractionSeconds = (args.length > 1) ? Double.parseDouble(args[1]) : 1.0;
        double distance = calculateDistractionDistance(mph, distractionSeconds);
        System.out.println(String.format("You will travel %10.3f feet if you are distracted for %10.3f distractionSeconds at %10.3f mph", distance, distractionSeconds, mph));
    }

    private DistractionDistanceCalculator() {
    }

    public static double calculateDistractionDistance(double mph, double distractionSeconds) {
        if (mph < 0.0) throw new IllegalArgumentException("Speed must be positive");
        if (distractionSeconds < 0.0) throw new IllegalArgumentException("Distraction seconds must be positive");
        return mph*FEET_PER_MILE/SECONDS_PER_HOUR*distractionSeconds;
    }
}
duffymo
  • 305,152
  • 44
  • 369
  • 561