-
Need help
Code:
//This class demonstrates the Distance.java class
//Branden Sullivan
import java.util.Scanner;
public class DistanceDemo
{
public static void main(String[] args)
{
//allows the user to type in the amount of miles
Scanner keyboard = new Scanner (System.in);
//variables are declared here
double newMiles;
Distance problem = new Distance("dist");
//aquiring the miles
System.out.print("How many miles? ");
newMiles = keyboard.nextDouble();
//telling the user if they have entered a invalid number
if(newMiles < 0){
newMiles = 0;
System.out.println("You have entered an invalid number and the miles will be set to zero.");
}
if(newMiles > 0){
System.out.println("There are " + problem.convertToFeet() + " feet in " + problem.getMiles() + " miles");
}
//acquiring another set of miles
System.out.print("Enter another number of miles to conver to feet: ");
newMiles = keyboard.nextDouble();
//telling the user if they have entered a invalid number
if(newMiles < 0){
newMiles = 0;
System.out.println("You have entered an invalid number and the miles will be set to zero.");
}
if(newMiles > 0){
System.out.println("There are " + problem.convertToFeet() + " feet in " + problem.getMiles() + " miles");
}
}
}
this is what i have so far. this worksheet says to call for the mutator method to change the number of miles in the distance object and to call the accessor method and the conversion method to display the information with the appropriate labels
-
this is my other class
Code:
public class Distance
{
//variables are declared here
private double Miles;
private double convertToFeet;
public Distance(String dist){
}
public void setMiles(double newMiles){
Miles = newMiles;
}
public double getMiles(){
return Miles;
}
public double convertToFeet(){
convertToFeet = Miles * 5280;
return convertToFeet;
}
}
-
are you having trouble with the calls or writing the methods or what? You haven't actually asked a question.