質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

1回答

264閲覧

Java で以下のコードを書いています。 なぜエラーになるのかわかりません。助けてください。

DaiseiIto

総合スコア6

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2017/11/17 17:39

以下の課題について質問です。
The local Driver's license office has asked you to write a program that grades the written portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers:
1.B 2.D 3.A 4.A 5.C 6.A 7.B 8.A 9.C 10.D 11.B 12.C 13.D 14.A 15.D 16.C 17.C 18. B 19. D 20. A

A student must correctly answer 15 of 20 questions to pass the exam.
Write a class named DriverExam that holds the correct answers to the exam in array field. The class should also have an array field that holds the student's answers.The class should have the following methods.

・passed. Return true if the student passed the exam, or false if the student failed
・totalCorrect. Returns the total number of correctly answered questions
・totalIncorrect. Returns the total number of ncorrectly answered questions
・questionMissed. An int array containing the question numbers of the question that the student missed
Demonstrates the class in a complete program that ask the user to enter a student's answer, and then displays the results returned form the DriverExam class7s mathods```

import

1 2 3public class DriverExam 4{ 5 public static void main(String[] args) 6 { 7 8 //Create an ArrayList to hold some names. 9 ArrayList<String> nameList = new ArrayList<String>(); 10 11 //Add some names to the ArrayList 12 char[] correct = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 13 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' }; 14 char[] respose = new char[20]; 15 int numCorrect[]; 16 int numIncorrect[]; 17 int[] Questioned; 18 boolean passed; 19 for (int a = 0; a < respose.length ; a++) 20 { 21 Stdout.println (); 22 23 passed = examPassed (response, correct); 24 numCorrect = totalCorrect (respose, correct); 25 numIncorrect = totalIncorrect (respose, numCorrect); 26 QuestMissed = questionsMissed (response, correct); 27 28 if (passed) 29 Stdout.print(" You passed "); 30 else 31 Stdout.print(" You did't pass!"); 32 33 Stdout.print(" Below are the details of your marked exam: "); 34 Stdout.print(" correct questions: " + numCorrect); 35 Stdout.print(" insorrect question: " + numIncorrect); 36 37 if (QuestMissed.length > 0); 38 { 39 Stdout.print(" QuestionMissed: "); 40 41 for (int a = 0 ; a < QuestMissed.length ; a++) 42 { 43 Stdout.print (QuestMissed.length [a]); 44 Stdout.print(" "); 45 } 46 } 47 } 48 private static int totalCorrect (char[] resp, char[] ans) ここにエラーが出ます。 49 { 50 int totalCor = 0; 51 for (int a = 0 ; a < resp.length ; a++) 52 { 53 if (resp [a] == ans [a]) 54 totalCor++; 55 } 56 return totalCor; 57 58 } 59 private static int[] toalIncorrect ( char[] resp, int right) 60 { 61 return (resp.length - right); 62 } 63 public static int[] questionMissed ( char[] resp, char[] ans); 64 int[] missedQuestions = {}; 65 66 if (sizeArray < 1) 67 return missedQuestions; 68 69 else 70 { 71 missedQuestions = new int [sizeArray]; 72 int position = 0; 73 for (int x = 0 ; x < sizeArray]; 74 { 75 if (resp [x] != ans [x]) 76 { 77 missedquestions [position] = (x + 1); 78 posotion = position + 1; 79 } 80 } 81 82 private static boolean examPassed (char[] resp, char[] ans) 83 { 84 int cor; 85 boolean flag = false; 86 cor = totalCorrect (resp, ans); 87 if (cor >= 15) 88 flag = true; 89 90 return flag; 91 } 92 } 93ここに言語を入力 94コード

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

swordone

2017/11/17 17:50

どのようなエラーが出ているかを書いてください
guest

回答1

0

java

1public class DriverExam { 2 public static void main(String[] args) { 3 4 //Create an ArrayList to hold some names. 5 ArrayList<String> nameList = new ArrayList<String>(); 6 7 //Add some names to the ArrayList 8 char[] correct = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 9 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' }; 10 char[] respose = new char[20]; 11 int numCorrect[]; 12 int numIncorrect[]; 13 int[] Questioned; 14 boolean passed; 15 // for① 16 for (int a = 0; a < respose.length ; a++) { 17 Stdout.println (); 18 19 passed = examPassed (response, correct); 20 numCorrect = totalCorrect (respose, correct); 21 numIncorrect = totalIncorrect (respose, numCorrect); 22 QuestMissed = questionsMissed (response, correct); 23 24 if (passed) 25 Stdout.print(" You passed "); 26 else 27 Stdout.print(" You did't pass!"); 28 29 Stdout.print(" Below are the details of your marked exam: "); 30 Stdout.print(" correct questions: " + numCorrect); 31 Stdout.print(" insorrect question: " + numIncorrect); 32 33 if (QuestMissed.length > 0); 34 { 35 Stdout.print(" QuestionMissed: "); 36 37 for (int a = 0 ; a < QuestMissed.length ; a++) { 38 Stdout.print (QuestMissed.length [a]); 39 Stdout.print(" "); 40 } 41 } 42 }// ここはfor文①の閉じで、まだmainメソッドが継続中 43 44 private static int totalCorrect (char[] resp, char[] ans) { 45 int totalCor = 0; 46 for (int a = 0 ; a < resp.length ; a++) { 47 if (resp [a] == ans [a]) 48 totalCor++; 49 } 50 return totalCor; 51 } 52 53 private static int[] toalIncorrect ( char[] resp, int right) 54{ 55return (resp.length - right); 56} 57public static int[] questionMissed ( char[] resp, char[] ans); 58int[] missedQuestions = {}; 59 60if (sizeArray < 1) 61return missedQuestions; 62 63else 64{ 65missedQuestions = new int [sizeArray]; 66int position = 0; 67for (int x = 0 ; x < sizeArray]; 68{ 69if (resp [x] != ans [x]) 70{ 71missedquestions [position] = (x + 1); 72posotion = position + 1; 73} 74} 75 76private static boolean examPassed (char[] resp, char[] ans) 77{ 78int cor; 79boolean flag = false; 80cor = totalCorrect (resp, ans); 81if (cor >= 15) 82flag = true; 83 84return flag; 85} 86}

途中まで適宜インデント入れてみましたが、これだけで原因は一目瞭然。
mainメソッド中にtotalCorrectなどのメソッドが存在しています。

加えて、Stdoutって何でしょう?

投稿2017/11/17 17:57

編集2017/11/17 17:59
swordone

総合スコア20649

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問