QuestionAsk Questions?

View Answers

October 21, 2009 at 10:39 AM

Hi Friend,

Try the following code:

import java.util.*;

public class RaceCar{

double hw;

double weight;

double milesPerGal;

double zeroTo60;

public RaceCar(double hw,double weight,double milesPerGal,double zeroTo60){

this.hw=hw;

this.weight=weight;

this.milesPerGal=milesPerGal;

this.zeroTo60=zeroTo60;

}

public void setHw(double hw){

this.hw=hw;

}

public double getHw(){

return hw;

}

public void setWeight(double weight){

this.weight=weight;

}

public double getWeight(){

return weight;

}

public void setMilesPerGal(double milesPerGal){

this.milesPerGal=milesPerGal;

}

public double getMilesPerGal(){

return milesPerGal;

}

public void setZeroTo60(double zeroTo60){

this.zeroTo60=zeroTo60;

}

public double getZeroTo60(){

return zeroTo60;

}

public double calculateTime(){

double acceleration=0.167/zeroTo60;

return Math.sqrt(2 * 0.25 / acceleration);

}

public static void main(String[]args){

Scanner input=new Scanner(System.in);

System.out.println("Enter horse power for car 1 between the range 200 to 700 hp");

double hw1=input.nextDouble();

System.out.println("Enter weight for car 1 between the range 1000 to 3000 pounds.");

double w1=input.nextDouble();

System.out.println("Enter horse power for car 2 between the range 200 to 700 hp");

double hw2=input.nextDouble();

System.out.println("Enter weight for car 2 between the range 1000 to 3000 pounds.");

double w2=input.nextDouble();

double zeroTo60CarA=w1/hw1/0.7;

double zeroTo60CarB=w2/hw2/0.7;

RaceCar car1=new RaceCar(hw1,w1,0.25,zeroTo60CarA);

double time1=car1.calculateTime();

System.out.println("Time taken by car 1= "+time1);

RaceCar car2=new RaceCar(hw2,w2,0.25,zeroTo60CarB);

double time2=car2.calculateTime();

System.out.println("Time taken by car 2= "+time2);

}

}

Thanks

Try the following code:

import java.util.*;

public class RaceCar{

double hw;

double weight;

double milesPerGal;

double zeroTo60;

public RaceCar(double hw,double weight,double milesPerGal,double zeroTo60){

this.hw=hw;

this.weight=weight;

this.milesPerGal=milesPerGal;

this.zeroTo60=zeroTo60;

}

public void setHw(double hw){

this.hw=hw;

}

public double getHw(){

return hw;

}

public void setWeight(double weight){

this.weight=weight;

}

public double getWeight(){

return weight;

}

public void setMilesPerGal(double milesPerGal){

this.milesPerGal=milesPerGal;

}

public double getMilesPerGal(){

return milesPerGal;

}

public void setZeroTo60(double zeroTo60){

this.zeroTo60=zeroTo60;

}

public double getZeroTo60(){

return zeroTo60;

}

public double calculateTime(){

double acceleration=0.167/zeroTo60;

return Math.sqrt(2 * 0.25 / acceleration);

}

public static void main(String[]args){

Scanner input=new Scanner(System.in);

System.out.println("Enter horse power for car 1 between the range 200 to 700 hp");

double hw1=input.nextDouble();

System.out.println("Enter weight for car 1 between the range 1000 to 3000 pounds.");

double w1=input.nextDouble();

System.out.println("Enter horse power for car 2 between the range 200 to 700 hp");

double hw2=input.nextDouble();

System.out.println("Enter weight for car 2 between the range 1000 to 3000 pounds.");

double w2=input.nextDouble();

double zeroTo60CarA=w1/hw1/0.7;

double zeroTo60CarB=w2/hw2/0.7;

RaceCar car1=new RaceCar(hw1,w1,0.25,zeroTo60CarA);

double time1=car1.calculateTime();

System.out.println("Time taken by car 1= "+time1);

RaceCar car2=new RaceCar(hw2,w2,0.25,zeroTo60CarB);

double time2=car2.calculateTime();

System.out.println("Time taken by car 2= "+time2);

}

}

Thanks

Related Tutorials/Questions & Answers: