Ok 사용자가 특정 키를 입력하면 프로그램 섹션을 이전 섹션으로 되돌릴 수있는 방법을 찾는 데 문제가 있습니다. 예를 들어, 언제든지 w를 누르면 프로그램은 체중 섹션으로 이동하여 새로운 체중을 입력 할 수 있고 h는 높이를 입력 할 수 있습니다. 너희들이 나에게 몇 가지 제안을 해줄 수 있다면 나는 그것을 고맙게 생각할 것이다. 너희들 감사합니다.)값 반복 및 재 지정
package Assignments;
수입 java.util의를 *; 공용 클래스 assignment3 {
public static void main(String[] args) {
//Scanner
Scanner stdIn = new Scanner(System.in);
//Variables
final double METERS_TO_CM = 100; // The constant to convert meters to centimeters
final double BSA_CONSTANT = 3600; // The constant to divide by for bsa
double bmi; // Body Mass Index
double weight; // Weight in kilograms
double height; // Height in meters
String classification; // Classifies the user into BMI categories
double bsa; // Body surface area
System.out.print("Welcome to the BMI and BSA Calculator to begin enter weight in kilograms.");
weight = stdIn.nextDouble();
System.out.print("Enter height in meters: ");
height = stdIn.nextDouble();
bmi = weight/(height*height);
bsa = Math.sqrt(((height*METERS_TO_CM)*weight)/BSA_CONSTANT);
if (bmi < 18.5)
{
classification = "Underweight";
}
else if (bmi < 25)
{
classification = "Normal";
}
else if (bmi < 30)
{
classification = "Overweight";
}
else
{
classification = "Obese";}
System.out.println("Choose Options below to set height and weight");
System.out.println("Your classification is: " + classification);
System.out.println("(H)eight: " + height + " meters");
System.out.println("(W)eight: " + weight + " kilograms");
System.out.printf("BMI: %.1f\n", bmi);
System.out.printf("BSA: %.2f\n", bsa);
System.out.println("(Q)uit");
String response = stdIn.next();
switch (response.charAt(0)) {
case 'w': response = "Enter new weight: ";
weight = stdIn.nextDouble();
System.out.println("Choose Options below to set height and weight");
System.out.println("Your classification is: " + classification);
System.out.println("(H)eight: " + height + " meters");
System.out.println("(W)eight: " + weight + " kilograms");
System.out.printf("BMI: %.1f\n", bmi);
System.out.printf("BSA: %.2f\n", bsa);
System.out.println("(Q)uit"); break;
case 'h': response = "Enter new height";
height = stdIn.nextDouble();
System.out.println("Choose Options below to set height and weight");
System.out.println("Your classification is: " + classification);
System.out.println("(H)eight: " + height + " meters");
System.out.println("(W)eight: " + weight + " kilograms");
System.out.printf("BMI: %.1f\n", bmi);
System.out.printf("BSA: %.2f\n", bsa);
System.out.println("(Q)uit"); break;
case 'q': System.exit(0);
default:
System.out.println (response + "Is not a valid option please try again");
}
}
}
'그들이 어떤 시간에 프로그램이 체중 section'에 걸릴 필요가 w를 공격하는 경우 - 당신은이 작업을 수행하는 기능을 다시 전화해야 할 필요가 있다고 생각합니다. 키보드 이벤트가 트리거되고 눌려진 키 문자를 확인하고 해당 메서드를 호출합니다. – Mahesh
빠른 콜백 예제를 보여 주시겠습니까? 교수님은 아직 우리에게이 사실을 알려주지 못했으며 예제를 찾는 데 어려움을 겪고 있습니다. – Brad