CSE 110 – Assignment #5

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (3 votes)

Part 1: Writing Exercise: (5 pts)
Don’t change ANY codes or add any lines to the Assignment5.java (If changed, -5 Pts). Write the
answers in a comment block in your Quiz.java (Part 2). Download and look at the Assignment5.java, and
answer the following questions. This Assignment5.java is a test code for the Quiz class, which you are
asked to develop in the Part2.
a. Explain what this program is within 500 words. Using the keyword quiz and list up the task of
each command (A, B, …)
b. What is the quiz called, and what is the Quiz called?
c. List up all Quiz ‘s methods/constructors invoked in the Assignment5.java. (Show the line number
and name of method for each)
d. Explain in your words why the nextLine() methods are used instead of next( )?
e. Explain what is happened when the user type “?” command.
/*
a) This program is to …
b) The quiz is … , and Quiz is …
c) XXX(XXX)at line-5, XXX(xxx, xxx)at line-100, …
d) The nextLine() is required because …
e) It returns
Part 2: Programming (15 Pts)
This assignment is to write a class definition (not a program, there is no main method) named
Quiz (saved in a file Quiz.java). The class has the following instance variables:
private String question
private String choiceA
private String choiceB
private String choiceC
private String choiceD
private char correctAnswer
© 2018 Yoshihiro Kobayashi
The class must include the following constructor and methods: (If your class does not contain any
of the following methods, points will be deducted).
Method Description of the Method
public
Quiz(String, String, String,
String, String, char)
Initialize all instance variables with the inputs.
(2 Pts).
public String
displayQuiz()
Return the question and 4 choices in the
specific format (look at the samples). Don’t use
any System.out method but return the all items
as one single string data. (2 Pts)
public void
setQuestion (String)
Set/update the question (1 Pts)
public void
setChoices (String, String,
String, String)
Set/Update the four choices. (1 Pts)
public void
setCorrectAnswer(char)
Set the correct answer (1 Pt)
private String
getChoice (char)
This is not a regular getter method. It returns
one of the questions corresponding to the input
character. e.g. getChoice(‘C’) returns the
choiceC. (3 Pts)
public void
randomize(String )
Change the order of questions by the input
string, and update the correct answer matching
to the new order. For example, “BACD” input
swap the choiceA and choiceB.
The following is the pseudo code. (3 Pts)
1) Get and keep the index of correct answer
letter in the input.
2) Use the getChoice(char) for each letter of
input, and set the new four choices.
3) Update the correct answer letter from
“ABCD” using the index obtained in 1).
public boolean
isCorrect (char)
Check if the input character is same as the
correct answer. (2 Pts)
This assignment has only one task, but the development process is decomposed into several steps.
Follow the instruction one by one. Don’t go to the next step if your program does not return the
proper output in each step.
Step 1: Check the Assignment5.java
Compile and run the Assignment5.java. You MUST have error messages because another class is
required to compile the code. Don’t change anything in the Assignment5.java during this
© 2018 Yoshihiro Kobayashi
homework. If you change any code, you lose 5 Pts. Go to the next step and start to implement
the Quiz.java.
Step 2: Develop a class with dummy methods
Make a new file and save it a Quiz.java in the same location as Assginment5.java. Create all
required instance variables and methods with dummy (no error code) statements in the class.
Keep empty in the void-type method, and make only one return statement in the return-type
method. The Quiz class with dummy statements looks like below.
Once all dummy methods are finished, compile the Quiz.java and Assignment5.java in your
development environment. Run (execute) the Assignment5 after both files are complied. If it
works, submit the both java files to the online site. You will see the following output, which
run without any error, but nothing is done because all methods are dummy so far.
Dummy Program Output (No compile error but do nothing)
****** Tester Program ******
Command Options ——————-A: Test the quiz
B: Edit the question
C: Edit the choices
R: Randomize the choices
Q: Quit the program
?: Display this menu
———————————–Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
B [Edit the question]
© 2018 Yoshihiro Kobayashi
[Type a question]:
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
C [Edit the first choice]
[Type the first choice A]:
[Type the second choice B]:
[Type the third choice C]:
[Type the forth choice D]:
[Type the correct answer]:
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
A [Test the quiz!]
[Type A, B, C or D]
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
A [Test the quiz!]
[Type A, B, C or D]
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
A [Test the quiz!]
[Type A, B, C or D]
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
R [Randomize the choices]
[Type a random pattern like a BACD ]:
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
A [Test the quiz!]
[Type A, B, C or D]
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
A [Test the quiz!]
[Type A, B, C or D]
© 2018 Yoshihiro Kobayashi
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
Command Options ——————-A: Test the quiz
B: Edit the question
C: Edit the choices
R: Randomize the choices
Q: Quit the program
?: Display this menu
———————————–Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)
****** End of Program ******
Step 3: Complete Methods
Now it is time to start the real programming. Complete all constructor and methods required in the
table above. If it works in your environment, submit the both java files to the online site, and
check if your output is the same as the output example.
Example Execution:
The following are example inputs and outputs. The user inputs are shown in red (which is not
seen online submission). Make your own questions rather than the examples.
Program Input
B
What is 3 + 5?
C
8
9
10
11
A
A
B
A
C
A
A
R
BADC
A
A
A
© 2018 Yoshihiro Kobayashi
B
?
Q
Program Output
****** Tester Program ******
Command Options ——————-A: Test the quiz
B: Edit the question
C: Edit the choices
R: Randomize the choices
Q: Quit the program
?: Display this menu
———————————–Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) B
B [Edit the question]
[Type a question]: What is 3 + 5?
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) C
C [Edit the first choice]
[Type the first choice A]: 8
[Type the second choice B]: 9
[Type the third choice C]: 10
[Type the forth choice D]: 11
[Type the correct answer]: A
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit)A
A [Test the quiz!]
Q: What is 3 + 5?
A): 8
B): 9
C): 10
D): 11
[Type A, B, C or D] B
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) A
A [Test the quiz!]
Q: What is 3 + 5?
A): 8
B): 9
C): 10
D): 11
[Type A, B, C or D] C
© 2018 Yoshihiro Kobayashi
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) A
A [Test the quiz!]
Q: What is 3 + 5?
A): 8
B): 9
C): 10
D): 11
[Type A, B, C or D] A
Good Job!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) R
R [Randomize the choices]
[Type a random pattern like a BACD ]: BADC
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) A
A [Test the quiz!]
Q: What is 3 + 5?
A): 9
B): 8
C): 11
D): 10
[Type A, B, C or D] A
No!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) A
A [Test the quiz!]
Q: What is 3 + 5?
A): 9
B): 8
C): 11
D): 10
[Type A, B, C or D] B
Good Job!
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) ?
Command Options ——————-A: Test the quiz
B: Edit the question
C: Edit the choices
R: Randomize the choices
Q: Quit the program
?: Display this menu
———————————–<= "BADC" with no space betwen letters! © 2018 Yoshihiro Kobayashi
Please input a command: (A:Quiz, B:Edit question, C:Edit choices,
R:Randomize, Q:quit) Q
****** End of Program ******
NOTE:
• Make only one scanner object using System.in. If your program does not run correctly
because of this issue, you lose some points (-3Pts).
• Use only the Java statements that have been covered in class to date. DO NOT use any other
items out of the Chapter 1 – 5, 8 (Array, ArrayList, exit() etc.). If in doubt, ask the instructor.
If you use them, then you lose the points of task. Complete each step one by one.
• Don’t copy any code developed by others.
• Don’t give your code to your classmates.
• Don’t use any algorithm, which you cannot understand.
• Your assignment file is checked by the MOSS (by Stanford Univ.), which is a program to detect
cheatings.
• Also we have the world-wide hot lines to detect cheating/violation using online support services
such as freelancer.com and makemoney.com.
/**********************************************************************************
Submit your homework by following the instructions below:
**********************************************************************************/
• Go to the course web site (my.asu.edu), and then click on the on-line Submission tab. Log in the site,
which was registered at the first Lab session. Make sure you use the correct email address for registration.
This will allow you to submit assignments. Please use your ASU e-mail address.
• Submit the template Assignment5.java and your Quiz.java files on-line. Make sure to choose HW5
from drop-down box.
• The Quiz.java should have the following, in order:
• In comments, the assignment Header described in “Important Note”.
• In comments, the answers to questions presented in Part#1.
• The working Java code requested in Part #2.
• The file must compile and run as you submit it. You can confirm this by viewing your submission
results.
Important Note: You may resubmit as many times as you like until the deadline, but we will only mark
your last submission. NO LATE ASSIGNMENTS WILL BE ACCEPTED.