مرحبا ,, كيفكم ؟
انا عندي برنامج يحول جميع القياسات بس في مشكلة عندي في METHOD RANGE
و هذا السؤال
? A method that Converts from Celsius to Fahrenheit
public static double celsiusToFahrenheit (double celsius)
?
A method that converts from Fahrenheit to Celsius
public static double fahrenheitToCelsius(double fahrenheit)
?
A method that converts from Feet to Meters
public static double feetToMeter (double feet)
?
A method that converts from Meter To Feet
public static double meterToFeet(double meter)
?
A method that converts from Kilogram to Pound
public static double kgToPound (double Kilogram)
?
A method that converts from Pound to Kilogram
public static double poundToKg(double pound)
?
A method that converts milliseconds to hours, minutes and seconds. Look at exercise 5.25
public static String convertMillisToTime(long millis)
?
A method that converts hours, minutes and seconds to milliseconds
public static long convertTimetoMillis(int hours, int minutes, int seconds)
?
هنا المشكلة في ال convert range method
A method that Convert range. This method converts from one measure to another using a range of values. The method accepts four inputs, startingValue, endingValue, incrementStep, conversionMethodName. The method prints a conversion table as explained in the following example. Let's assume that we invoke the method with the parameters
هنا لازم على اليوزر انه يظهر هذه القائمة و ما يعادلها في الفهرنهايت
(31, 40, 1, "celsiusToFahrenheit" ) , then the method will print the following table.
Celsius Fahrenheit
40 105.0
39 102.2
.... .......
32 89.6
31 87.8
Hint: Use overloaded method to call the proper conversion method. **/
- ?
getUserChoise method. This method displays the following menu to the user and accepts his/her choice:
Conversion Menu
1
1 Convert from Celsius to Fahrenheit
2
2 Convert from Fahrenheit to Celsius
3
3 Convert from Feet to Meters
4
4 Convert from Meter To Feet
5
5 Converts from Kilogram to Pound
6
6 Converts from Pound to Kilogram
7
7 Convert milliseconds to hours, minutes and seconds.
8
8 Convert hours, minutes and seconds to milliseconds
9
9 Convert range.
10
10 Quit
**/
- ?
The main method will be running in a infinite loop invoking getUserChoise method. Then the method accepts the proper input and invokes the proper method according to user choice. When user choice is Quit then the program will terminate. In case of Convert range choice a sub menu is displayed to ask the user to choose the conversion method.
و هذا كودي اللي اشتغلت عليه
public class conversionTool{
/**
* Main routine runs a loop that shows the menu, get the user's
* choice, and responds.
*/
public static void main(String[] args) {
int menuChoice; // The number of the option that the user
// selects from the menu.
double celsius; // The Celsius temperature measurement.
double fahrenheit; // The Fahrenheit temperature measurement.
double feet; // The Feet tempreture measurement.
double meter; // The Meter tempreture measurement .
double Kilogram; // The Meter tempreture measurement.
double pound; // The Meter tempreture measurement.
while (true) {
System.out.println();
showMenu();
System.out.print("Enter the number your choice (1, 2, or 3): ");
menuChoice = TextIO.getlnInt();
if (menuChoice == 1) {
// Convert Fahrenheit to Celsius.
System.out.print("\nEnter temperature in degrees Fahrenheit: ");
fahrenheit = TextIO.getlnDouble();
celsius = fahrenheitToCelsius(fahrenheit);
System.out.println(fahrenheit + " degrees Fahrenheit is "
+ celsius + " degrees Celsius");
}
else if (menuChoice == 2) {
// Convert Celsius to Fahrenheit.
System.out.print("\nEnter temperature in degrees Celsius: ");
celsius = TextIO.getlnDouble();
fahrenheit = celsiusToFahrenheit(celsius);
System.out.println(celsius + " degrees Celsius is "
+ fahrenheit + " degrees Fahrenheit");
}
else if (menuChoice == 3) {
// Convert Feet to Meters.
System.out.print("\nEnter lenght in Feet: ");
feet = TextIO.getlnDouble();
meter = feetToMeter(feet);
System.out.println(feet + " Feet length is " + meter + " Meter lenght");
}
else if (menuChoice == 4) {
// Convert Meters to Feet.
System.out.print("\nEnter lenght in Meter: ");
meter = TextIO.getlnDouble();
feet = meterToFeet(meter);
System.out.println(meter + " meter length is " + feet + " feet length");
}
else if (menuChoice == 5) {
// Convert Kilogram to Pound.
System.out.print("\nEnter Weight in kilogram: ");
Kilogram = TextIO.getlnDouble();
pound = kgToPound (Kilogram);
System.out.println(Kilogram + " weight in Kilogram " + pound + " weight in pound");
}
else if (menuChoice == 6) {
// Convert Pound to Kilogram.
System.out.print("\nEnter Weight in kilogram: ");
pound = TextIO.getlnDouble();
Kilogram = kgToPound (pound);
System.out.println(pound + " weight in pound " + Kilogram + " weight in Kilogram");
}
else if (menuChoice == 7) {
// exit from while loop and end program
break;
}
else {
System.out.println("Sorry, " + menuChoice + " is not a valid option.");
System.out.println("Please try again.");
System.out.println();
}
} // end while
System.out.println("\nOK. Exiting from program.\n");
} // end main()
public static double celsiusToFahrenheit(double celsius){
double fahrenheit;
fahrenheit = (celsius - 32)* (5.0/9.0);
return fahrenheit;
}
public static double fahrenheitTocelsius(double fahrenheit){
double celsius;
celsius = (celsius + 32)* (5.0/9.0);
return celsius;
}
public static double feetToMeter(double feet){
double feet;
meter = (feet * 0.3048);
return meter;
}
public static double meterToFeet(double meter){
double meter;
feet = (feet * 3.2808);
return feet;
}
public static double kgToPound (double Kilogram){
double Kilogram;
pound = (Kilogram * 2.2046);
return pound;
}
public static double poundTokg (double pound){
double pound;
Kilogram = (pound * 0.4536);
return Kilogram;
}سوري على عدم الايضاح ,, بس المشكلة في الكونفرت ميثود و القيت يوزر ميثود ما عرفت كيف اشتغل عليهم ,, اتمنى اني وضحته لكم
