Results 1 to 3 of 3
Thread: Need help
- 10-19-2009, 07:12 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
Need help
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 labelsJava 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"); } } }
- 10-19-2009, 07:13 PM #2
Member
- Join Date
- Oct 2009
- Posts
- 49
- Rep Power
- 0
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; } }
- 10-19-2009, 07:45 PM #3
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.


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks