الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[مخالف]عاجل و ضروري الله يخليكم

مغلق
بدأه areej ahmad في 6 أبريل 2008 · 7 رد · 803 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

ما هو الخطأ في هذا البرنامج

import javax.swing.JOptionPane;




public class conversionTool1{


  /**
	*   Main routine runs a loop that shows the menu, get the user's
	*   choice, and responds.
	*/
 public static String getUserChoice(){
  String input;  int inputInInteger;
  input=JOptionPane.showInputDialog(null,  "1-   Convert from Celsius to Fahrenheit\n"+
			 "2-   Convert from Fahrenheit to Celsius\n"+
				   "3-   Convert from Feet to Meter\n"+
							"4-   Convert from Meter to feet\n"+
				   "5-   Convert from Kilogram to Pound\n"+
				   "6-   Convert from Pound to Kilogram\n"+
				   "7-   Convert from Milliseconds to hours, minutes and seconds\n"+
				   "8-   Convert from hours, minutes and seconds to Milliseconds\n"+
				   "9-   Convert Range\n"+
				   "10-  Quit\n"+
				   "Enter your choice:","Conversion Menu", JOptionPane.QUESTION_MESSAGE);

  return input;
 }

 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.
   long millis;		 
  final int IN_HOUR;
  final int IN_MINUTE;
  final int IN_SECOND;


	while (true) {

		 System.out.println();
		 while(getUserChoice()!="10"){
		 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==8){
			 public static long convertTimetoMillis(int hours, int minutes, int seconds){
			  final int IN_HOUR=3600000;
			  final int IN_MINUTE=60000;
			  final int IN_SECOND=1000;
			  return((long)(hours*IN_HOUR)+(minutes*IN_MINUTE)+(seconds*IN_SECOND));
			 }// end of T->M
			}


			 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) {		
	// To convert Celsius to Fahrenheit, multiply by 1.8 and add 32 degrees. 
	double fahrenheit = celsius * 1.8 + 32;
	return fahrenheit;
}

public static double fahrenheitTocelsius(double fahrenheit) {
	// To convert Fahrenheit to Celsius, subtract 32 degrees and divide by 1.8.		 
	double celsius = (fahrenheit - 32) / 1.8;
	return celsius;
}

public static double feetToMeter(double feet) {
	// 1 foot = 0.3048 meters		
	double meter = feet * 0.3048;
	return meter;
}

public static double meterToFeet(double meter) {
	// 1 meter = 3.2808399 feet
	double feet = meter * 3.2808;
	return feet;
}

public static double kgToPound(double Kilogram) {
	// 1 kilogram = 2.20462262 pounds
	double pound = Kilogram * 2.2046;
	return pound;
}

public static double poundTokg(double pound) {
	// 1 pound = 0.45359237 kilograms	
	double Kilogram = pound * 0.4536;
	return Kilogram;
}


public static String convertMillisToTime(long millis)
{
	int milliseconds = (int)(millis % 1000);
	int seconds = (int)((millis/1000) % 60);
	int hours = (int)((millis/3600000) % 24);
	String millisecondsStr = (milliseconds<10 ? "00" : (milliseconds<100 ? "0" : ""))+milliseconds;
	String secondsStr = (seconds<10 ? "0" : "")+seconds;
	String hoursStr = (hours<10 ? "0" : "")+hours;
	return new String(hoursStr+":"+secondsStr+"."+millisecondsStr);
}

public static long convertTimetoMillis(int hours, int minutes, int seconds){

 return((long)(hours*3600000)+(minutes*60000)+(seconds*1000));
}// end of T->M

public static void convertRange(int startingValue, int endingValue, int incrementStep, String conversionMethodName){
if(conversionMethodName.equalsIgnoreCase("celsiusToFahrenheit")){
System.out.println("Celsius"+"\t"+"Fahrenheit");
for (int step = startingValue; step <= endingValue; step += incrementStep) {
System.out.println(step+"\t"+celsiusToFahrenheit(step));
}
} 

else if(conversionMethodName.equalsIgnoreCase("fahrenheitTocelsius")){
System.out.println("Fahrenheit"+"\t"+"Celsius");
for (int step = startingValue; step <= endingValue; step += incrementStep) { 
System.out.println(step+"\t"+fahrenheitTocelsius(step));
}
}


if(conversionMethodName.equalsIgnoreCase("feetToMeter")){
System.out.println("feet"+"\t"+"meter");
for (int step = startingValue; step <= endingValue; step += incrementStep) {
System.out.println(step+"\t"+feetToMeter(step));
}
}

if(conversionMethodName.equalsIgnoreCase("meterToFeet")){
System.out.println("meter"+"\t"+"feet");
for (int step = startingValue; step <= endingValue; step += incrementStep) {
System.out.println(step+"\t"+meterToFeet(step));
}
}


if(conversionMethodName.equalsIgnoreCase("kgToPound")){
System.out.println("Kilogram"+"\t"+"pound");
for (int step = startingValue; step <= endingValue; step += incrementStep) {
System.out.println(step+"\t"+kgToPound(step));
}
}

if(conversionMethodName.equalsIgnoreCase("poundTokg")){
System.out.println("pound"+"\t"+"Kilogram");
for (int step = startingValue; step <= endingValue; step += incrementStep) {
System.out.println(step+"\t"+poundTokg(step));
}
}

if(conversionMethodName.equalsIgnoreCase("convertMillisToTime")){
System.out.println("millis"+"\t"+"millisecond"+"\t"+"seconds"+"\t"+"hours");
for (int step = startingValue; step <= endingValue; step += incrementStep) {
System.out.println(step+"\t"+convertMillisToTime(step));
}
}

if(conversionMethodName.equalsIgnoreCase("convertTimetoMillis")){
System.out.println("hours"+"\t"+"minutes"+"\t"+"seconds"+"\t"+"millis");
for (int step = startingValue; step <= endingValue; step += incrementStep) {
System.out.println(step+"\t"+convertTimetoMillis(step));
}
}
#2

يا أختي لماذا لا تضعي عنوان جيد لمواضيعك

لسنا بصدد تعقيدك

لكن هذا الذي تقومين به سيساعد على تطور المنتدى

ثانياً: بالله عليك هل سأضطر لقراءة الشيفرة الخاصة بك بالكمال لكي أساعدك

لماذا لا تسهلي علينا الموضوع

أذكري نبذة عن مشكلتك

لمصلحتك فقط

لو كنت تظنين أن المنتدى هنا فقط لخدمتك فهذه مشكلة

ثم لماذا تفتحي أكثر من موضوع

ألم يكن هناك موضوع قد فتحته من قبل

بصراحة لا تلومي أحد على إغلاق مواضيعك

فأنتي السبب

تحياتي

الله معك

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3

مرحبا اخي alaadia

اولا : سوري على الازعاج و الخطأ ,, و لو انني لا ارى ان هناك خطأ ارتكبته ,, المنتدى لمساعدة اخوانك و اخواتك المبتدئين في البرمجة ( امثالي ) ,,

و ثانيا : لست مجبور اخي الكريم على الرد اذا كان الامر يزعجك ,,

و جزاك الله خيرا على كل حال

#4

يبدو أنك أسأتي فهمي

على العموم الموضوع يعود لك

عندما تريدين مساعدة من أحدهم

فقدمي له الأسباب كي يساعدك

لا أعني نفسي بذلك

أعني أعضاء المنتدى بشكل عام

أريد أن أساعدك

لكني لا أملك الوقت

أقضيه في قراءة شيفرتك

هل فهمتي ما أرموا إليه؟؟؟

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#5

في الخيار هذا :

else if (menuChoice==8){

convertTimetoMillis(int hours, int minutes, int seconds){

final int IN_HOUR=3600000;

final int IN_MINUTE=60000;

final int IN_SECOND=1000;

return((long)(hours*IN_HOUR)+(minutes*IN_MINUTE)+(seconds*IN_SECOND));

}// end of T->M

}

ماهي قيمة الساعة والدقيقة والثانية المرسلة ... وكيف يستفبل هذا الخيار متغيرات ليس لها قيم ولكن معرفة ويقوم باجراء العمليات عليها

#6

لو تضعي رسالة الغلط اللي تظهر لك بعد التنفيذ ومن خلالها ممكن ايجاد الغلط

يعني

the error message

#7

يرجى من الاعضاء عدم المساعدة في المواضيع المخالفة لان ذلك سيشجع عدم الاكتراث لديهم بما انهم يحصلون على ما يريدون

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#8

تأسف إدارة الفريق العربي لغلق الموضوع وذلك لمخالفته قوانين المشاركات .

قواعد طرح المشاركات

/index.php?showtopic=29343

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

هذا الموضوع مغلق.

مواضيع مشابهة