advice with javascript Class Converter

prompts meter measurements, converting to Miles, Feet, and Inches

Page 1 of 1

1 Replies - 6404 Views - Last Post: 01 May 2009 - 11:02 PM

#1 Jvaughan79  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-April 09

advice with javascript Class Converter

Posted 14 April 2009 - 08:24 PM

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



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


Is This A Good Question/Topic? 0
  • +

Replies To: advice with javascript Class Converter

#2 rharriso  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 45
  • Joined: 29-April 09

Re: advice with javascript Class Converter

Posted 01 May 2009 - 11:02 PM

This is the Javascript forum. You posted a java question.`

Besides, I tested out your code and it seems to run fine. I don't really see the problem? Can you not change this to output the right values or what?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1