1
사용자가 입력 한 리히터 스케일 값을 기반으로 한 지진 발생시 공제액 및 지불금을 결정하는 코드가 있습니다. 여기 내 코드가 현재 어떻게 생겼는지입니다.감시 제어 루프 및 여러 문자열을 출력하는 방법. 초보자 용 Java 프로그래밍
import java.util.Scanner;
public class RichterScaleDamage
{
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in);
String name = "";
char answer = 'Y';
double homeValue = 0;
double richterScale = 0;
double payout = 0;
double deductible = 0;
String coverage = "";
System.out.printf("\nPlease enter your name: ");
name = userInput.nextLine();
while(Character.toUpperCase(answer) == 'Y')
{
System.out.printf("\nPlease enter the insured value of your home: ");
homeValue = userInput.nextDouble();
userInput.nextLine();
System.out.printf("\nRichter Scale Description of Effect"
+"\n 8.0 Most structures fall"
+"\n 7.0 Many buildings destroyed"
+"\n 6.0 Many buildings considerably damaged, some collapse"
+"\n 4.5 Damage to poorly constructed buildings"
+"\n 3.5 Felt by many people, no destruction"
+"\n 0 Generally not felt by people\n\n");
System.out.printf("\nPlease enter the Richter scale value for the earthquake: ");
richterScale = userInput.nextDouble();
userInput.nextLine();
if(richterScale < 0)
{
System.out.printf("\nInvalid! Cannot enter negative values");
}
System.out.printf("\n\nEnter \'Y\' to continue with another calculation or \'N\' to exit: ");
answer = userInput.nextLine().charAt(0);
}
if(richterScale >= 8)
{
String message = "Most structures fall";
payout = homeValue * .85;
deductible = homeValue * .15;
coverage += String.format("\n%-50s %6s$%,20.2f"
+"\nDeductable%47s %,20.2f"
+"\n%46sTOTAL %4s $%,20.2f\n",
message, " ", payout, " ", deductible, " ", " ", payout + deductible);
System.out.printf("%s", coverage);
}
if(richterScale < 8 && richterScale >= 7)
{
String message = "Many buildings destroyed";
payout = homeValue * .75;
deductible = homeValue * .25;
coverage += String.format("\n%-50s %6s$%,20.2f"
+"\nDeductable%47s %,20.2f"
+"\n%46sTOTAL %4s $%,20.2f\n",
message, " ", payout, " ", deductible, " ", " ", payout + deductible);
System.out.printf("%s", coverage);
}
if(richterScale < 7 && richterScale >= 6)
{
String message = "Damage to poorly constructed buildings";
payout = homeValue * .75;
deductible = homeValue * .25;
coverage += String.format("\n%-50s %6s$%,20.2f"
+"\nDeductable%47s %,20.2f"
+"\n%46sTOTAL %4s $%,20.2f\n",
message, " ", payout, " ", deductible, " ", " ", payout + deductible);
System.out.printf("%s", coverage);
}
if(richterScale < 6 && richterScale >= 4.5)
{
String message = "Many buildings considerably damaged, some collapse";
payout = homeValue * .65;
deductible = homeValue * .35;
coverage += String.format("\n%-50s %6s$%,20.2f"
+"\nDeductable%47s %,20.2f"
+"\n%46sTOTAL %4s $%,20.2f\n",
message, " ", payout, " ", deductible, " ", " ", payout + deductible);
System.out.printf("%s", coverage);
}
if(richterScale < 4.5 && richterScale >= 3.5)
{
String message = "Felt by many people, no destruction";
payout = homeValue * .55;
deductible = homeValue * .45;
coverage += String.format("\n%-50s %6s$%,20.2f"
+"\nDeductable%47s %,20.2f"
+"\n%46sTOTAL %4s $%,20.2f\n",
message, " ", payout, " ", deductible, " ", " ", payout + deductible);
System.out.printf("%s", coverage);
}
if(richterScale < 3.5 && richterScale >= 0)
{
String message = "Generally not felt by people";
payout = homeValue * .0;
deductible = homeValue * .25;
coverage += String.format("\n%-50s %6s$%,20.2f"
+"\nDeductable%47s %,20.2f"
+"\n%46sTOTAL %4s $%,20.2f\n",
message, " ", payout, " ", deductible, " ", " ", payout + deductible);
System.out.printf("%s", coverage);
}
}
}
아직 채우기 위해 몇 가지 코드가 있습니다. 너무 많이 입력하면 죄송합니다. 사이트가 새로 생겼습니다. 사용자가 Y를 입력하면 다른 집의 다른 값과 함께 집에 가해진 피해 규모를 입력하게됩니다. 현재 출력물에는 입력 된 최신 값만 표시되며 다른 모든 값은 미리 표시되지 않습니다. 나는 내 책을 읽었으며, 최종 사용자 항목 이상을 표시하기 위해 출력물을 얻는 방법에 대해 꽤 당황 스럽다. 다음은 출력 예제입니다!
Please enter your name: Name Please enter the insured value of your home: 1000000 Richter Scale Description of Effect 8.0 Most structures fall 7.0 Many buildings destroyed 6.0 Many buildings considerably damaged, some collapse 4.5 Damage to poorly constructed buildings 3.5 Felt by many people, no destruction 0 Generally not felt by people Please enter the Richter scale value for the earthquake: 5 Enter 'Y' to continue with another calculation or 'N' to exit: y Please enter the insured value of your home: 349999 Richter Scale Description of Effect 8.0 Most structures fall 7.0 Many buildings destroyed 6.0 Many buildings considerably damaged, some collapse 4.5 Damage to poorly constructed buildings 3.5 Felt by many people, no destruction 0 Generally not felt by people Please enter the Richter scale value for the earthquake: 6 Enter 'Y' to continue with another calculation or 'N' to exit: n Damage to poorly constructed buildings $ 262,499.25 Deductable 87,499.75 TOTAL $ 349,999.00나는 사용자가 정보를 입력으로 마지막 부분만큼을 표시하고 싶습니다. 죄송합니다.이 용어를 이해하는 데 필요한 용어를 모르는 경우 나는 첫 번째 프로그래밍 코스에 있으며, 1 개월 만 학습했습니다. 이것을 이해하는 데 도움이 될 것입니다.
감사합니다,이 사실은 내가 원하는 결과를 얻었다! 루프를 나가기를 기다리면 사용자가 루프를 빠져 나오기를 기다리면 메시지가 출력됩니다. 논리가이 논리 뒤에 무엇인지 확실하지는 않지만 100 % 확실합니다. – ShiftyMcGrifty