기본적으로이 설문 조사 프로그램이 있으며 "if"문에 의해 주어진 응답과 일치하는 응답 된 질문의 비율을 계산하는 방법을 알고 싶습니다. 이 백분율은 사용자 유형에 따라 다를 수 있습니다. 또 다른 점은 아래 코드에서 이미 설정 및 주석 처리 된 비 기본 메소드에 백분율을 계산하기위한 코드를 넣어야한다는 것입니다 (비 기본 메소드로 레이블 지정). 내가 알고 싶은 것은 가능한 모든 사용자 입력 (설문 조사가 5 개의 질문이므로 기본적으로 1/5, 2/5, 3/5, 4/5 및 5/5)을 설명하는 수식을 만드는 방법입니다. 내가 제대로 이해 해요 경우자바에서 사용자 입력에 대한 백분율을 계산하는 방법
import java.util.Scanner;
public class VideogameSurveyFINAL {
//non-main method
private static void gamerpercentagelikeme (String[] args) {
int correct
}
//main method below
public static void main(String[] args) {
boolean run = true;
while(run){
System.out.println ("WELCOME TO THE GRAND SURVEY OF VIDEOGAMES!");
System.out.println ("");
Scanner keyboard = new Scanner(System.in);
//Q1
System.out.println("Question 1: Do you like Videogames? (Please answer Yes or No)");
String input = keyboard.nextLine();
if (input.equalsIgnoreCase("Yes")||input.equalsIgnoreCase("Yeah")||input.equalsIgnoreCase("Y")||input.equalsIgnoreCase("YES!")) {
System.out.println("Awesome!");
}
else {
System.out.println("Wow. You have no sense of fun.");
}
//Q2
System.out.println ("");
System.out.println("Question 2: What types of videogames do you play?(Please use abbreviated froms of games such as FPS, MMO, RPG etc).");
String input2 = keyboard.nextLine();
if (input2.equalsIgnoreCase("Fps")) {
System.out.println("Fantastic! Me too!");
}
else {
System.out.println("OK, thats cool!My favorite is FPS.");
}
//Q3
System.out.println ("");
System.out.println("Question 3:Do you like Singleplayer or Multiplayer games? ");
String input3 = keyboard.nextLine();
if (input3.equalsIgnoreCase("Singleplayer")||input.equalsIgnoreCase("S")||input.equalsIgnoreCase("SP")) {
System.out.println("Me Too!!");
}
else {
System.out.println("Rad! My favorite is Singleplayer. ");
}
//Q4
System.out.println ("");
System.out.println("Question 4: What do you like in a videogame");
String input4 = keyboard.nextLine();
if (input4.equalsIgnoreCase("I dont play games")||input.equalsIgnoreCase("None")||input.equalsIgnoreCase("N")) {
System.out.println("You are sooooo boring.");
}
else {
System.out.println("Awesome! What I like in a videogame is solid gameplay, great graphics and immersive audio...but most of all, IT HAS TO BE FUN!!");
}
//Q5
System.out.println ("");
System.out.println("Question 5: What is your ALL-TIME favorite videogame?");
String input5 = keyboard.nextLine();
if (input5.equalsIgnoreCase("Skyrim")) {
System.out.println("Really?! ME TOO!");
}
else {
System.out.println("Great! My personal favorite is SKYRIM!");
}
System.out.println ("");
System.out.println("THANK YOU FOR TAKING THE GRAND SURVEY OF VIDEOGAMES!");
System.out.println ("");
System.out.println ("Would you like to take the survey again? (Please answer with Yes or No: Case sensitive)");
String input6 = keyboard.nextLine();
if (input6.equalsIgnoreCase("No")) {
break;
}
else
{
System.out.println("Okay! The Survey will restart shortly.");
System.out.println ("");
System.out.println ("");
}
}
} }
백분율을 계산하는 방법을 알고 있습니까? 나는 일반적으로 (반드시 컴퓨터 프로그램에있는 것은 아닙니다) 의미합니다. – ajb
예 (부품을 전체로 나눈 값) * 100 –
가능한 입력 및 해당 백분율에 대해 배열을 만듭니다! 사용자가 대답을 입력 할 때 해당 대답을 증가시키고 마지막에는 백분율 계산을 수행하는 것이 쉬워야합니다. –