Quote
I honestly can't figure this out, I've spent more than 15 hours on this and its really frustrating.
I would really like some advice on better methods, or a better way to print out The code I have has no syntax erorrs, I honestly need an outsider to show me how stupid I am. I'm seriously lost with this one. If you have any suggestions please email me at jasonvaughan79@gmail.com
I would really like some advice on better methods, or a better way to print out The code I have has no syntax erorrs, I honestly need an outsider to show me how stupid I am. I'm seriously lost with this one. If you have any suggestions please email me at jasonvaughan79@gmail.com
This is the question that was asked.
Write a program that prompts the user for a measurement in meters and then converts it
into miles, feet, and inches. Use a class public class Converter
Constructs a converter that can convert between two units.
@param aConversionFactor the factor by which to multiply to convert to the target unit
public Converter(double aConversionFactor) { . . . }
Converts from a source measurement to a target measurement.
@param fromMeasurement the measurement
@return the input value converted to the target unit
public double convertTo(double fromMeasurement) { . . . }
Converts from a target measurement to a source measurement.
@param toMeasurement the target measurement
@return the value whose conversion is the target measurement
public double convertFrom(double toMeasurement) { . . . }
In your ConverterTester class, construct and test the following Converter object:
final double MILE_TO_KM = 1.609;
Converter milesToMeters = new Converter(1000 * MILE_TO_KM);
public class Converter
{
private double factor;
private double convertFrom;
private double convertTo;
private double aConversionFator;
private double fromMeasurment;
private double toMeasurement;
//Constructs a converter that can convert between two units.
//@param aConversionFactor the factor with which to multiply
//to convert to the target unit
public Converter(double aConversionFactor)
{
factor = aConversionFactor;
}
//Converts from a source measurement to a target measurement.
//@param fromMeasurement the measurement
//@return the input value converted to the target unit
public double convertTo(double fromMeasurement)
{
return fromMeasurement * factor;
}
public double convertFrom(double toMeasurement)
{
return toMeasurement / factor;
}
}
//Tester Class.
import java.util.Scanner;
public class ExP4_7
{
public static void main(String[] args)
{
final double MILE_TO_KM = 1.609;
final double FEET_TO_CM = 30.5;
final double INCHES_TO_CM = 2.54;
Converter milesToMeters = new Converter(1000 * MILE_TO_KM);
Converter feetToMeters = new Converter(FEET_TO_CM / 100);
Converter inchesToMeters = new Converter(INCHES_TO_CM / 100);
Scanner in = new Scanner(System.in);
System.out.print("Value here");
double value = in.nextDouble();
System.out.println(value + " miles = " + milesToMeters.convertTo(value) + " meters");
System.out.println(value + " feet: " + feetToMeters.convertTo(value) + " meters");
System.out.println(value + " inches: " + inchesToMeters.convertTo(value) + " meters");
}
}
This post has been edited by Jvaughan79: 14 April 2009 - 08:26 PM

New Topic/Question
Reply



MultiQuote




|