Results 1 to 3 of 3

Thread: Need help

  1. #1
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default Need help

    Java 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

  2. #2
    s_dawg101 is offline Member
    Join Date
    Oct 2009
    Posts
    49
    Rep Power
    0

    Default

    this is my other class

    Java 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;
    	}
     
     }

  3. #3
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    are you having trouble with the calls or writing the methods or what? You haven't actually asked a question.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •