CSE110 Assignment #5 Solved

35.00 $

Category:

Description

Rate this product

Topics

  • Object Oriented Programming (Chapter 8) – Encapsulation

    – Implementingclasses – Implementingmethods – Object construction
    – Constructors

  • Methods (Chapter 5)
    – Definition and Invocation.

    Important Note:

    All submitted assignments must begin with the descriptive comment block. To avoid losing trivial points, make sure this comment header is included in every assignment you submit, and that it is updated accordingly from assignment to assignment. (If not, -1 Pt)

    //*********************************************************** // Name: your name
    // Title: title of the source file
    // Description: Write the description in your words.

    // Time spent: how long it took you to complete the assignment // Date: the date you programmed //**********************************************************

Maximum points: 20 pts

Your programming assignments require individual work and effort to be of any benefit. Every student must work independently on his or her assignments. This means that every student must ensure that neither a soft copy nor a hard copy of their work gets into the hands of another student. Sharing your assignments with others in any way is NOT permitted. Violations of the University Academic Integrity policy will not be ignored. The university academic integrity policy is found at http://www.asu.edu/studentlife/judicial/integrity.html

Don’t use any paid tutoring service online. We have strong connections to the world-wide proctors on the site, and if you use it, very serious penalty (expel, cheating academic history, etc) will be given.

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.

b. c.

d. e.

Explain what this program is within 500 words. Using the keyword quiz and list up the task of each command (A, B, …)
What is the quiz called, and what is the Quiz called in OOP?
List up all Quiz ‘s methods/constructors invoked in the Assignment5.java. (Show the line number and name of method for each)

Explain in your words why the nextLine() methods are used instead of next( )? 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      answer

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 in the method, but return the all items as one single string data. Use “\n” for line-changes. (2 Pts)

public void setQuestion(String)

Set the question with the input. (1 Pts)

public void
set4Choices (String, String, String, String)

Set/override the four choices. (1 Pts)

public void setCorrectAnswer(char)

Set the correct answer (2 Pt)

String getChoice (char)

private

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 boolean isCorrect (char)

Check whether the input character is same as the correct answer. (2 Pts)

public void shuffle()

Change the order of questions, and update the correct answer matching to the new order. The following is the pseudo code. (2 Pts)

  1. 1)  Make a random list of 4 letters, A,B,C, and

    D such as “BDCA”.

  2. 2)  Reset the correct answer by finding the

    position of answer letter generated in the step above. Suppose that ‘B’ is the answer and random list is “BACD”. The correct answer is changed to the position 0, which will be the new choiceA. So the correct answer must be updated from B to A.

    BACD changes the choices as choiceB is changed to choiceA choiceA is changed to choiceB choiceC is changed to choiceC choiceD is changed to choiceD

  3. 3)  Update the choices by calling the getChoice(char) four times to get each choice, and reset the choices by using set4Choices(…) method.

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 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)

---------------
YOUR OUTPUT 1
----------------

 

 ****** Tester Program ******
Command Options --------------------
A: Test the quiz
B: Edit the question
C: Edit the choices

S: Shuffle the choices
Q: Quit the program
?: Display this menu ———————————— Please input a command:

(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, Q:quit) B [Edit the question]
[Type a question]:

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, 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, S:Shuffle, Q:quit)

     A [Test the quiz!]
     [Type A, B, C or D]
No!

… Continued to display the similar comments

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, Q:quit) Command Options ——————–
A: Test the quiz
B: Edit the question
C: Edit the choices
S: Shuffle the choices

Q: Quit the program
?: Display this menu ————————————

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, Q:quit)

 ****** End of Program ******

Step 3: Complete Methods

Now it is time to start the real missions. 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:(Not dummy but real program)

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. The output may be different from yours in green because the random letter is generated.

*) The shuffle() is a challenging question but only 2 points. If you cannot finish it, keep it as

a dummy to get the 90% of full points.

—————- INPUT 1 —————- B

What is 3 + 5?
C
8
9
10
11
A
A
B
A
C
A
A
S
A
A
A
B
?
Q
----------------
YOUR OUTPUT 1
----------------
 ****** Tester Program ******

Command Options ——————– A: Test the quiz
B: Edit the question
C: Edit the choices

S: Shuffle the choices

Q: Quit the program
?: Display this menu
————————————
Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, 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, S:Shuffle, 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, S:Shuffle, 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, S:Shuffle, 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 No!

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, 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, S:Shuffle, Q:quit) S

     S [Shuffle the choices]

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, Q:quit) A

     A [Test the quiz!]
Q: What is 3 + 5?
A): 10
B): 8
C): 11
D): 9

[Type A, B, C or D] A

No!

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, Q:quit) A

     A [Test the quiz!]
Q: What is 3 + 5?
A): 10
B): 8
C): 11
D): 9

[Type A, B, C or D] B

Good Job!

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, Q:quit) ? Command Options ——————–
A: Test the quiz
B: Edit the question
C: Edit the choices
S: Shuffle the choices
Q: Quit the program
?: Display this menu
————————————

Please input a command:
(A:Quiz, B:Edit question, C:Edit choices, S:Shuffle, 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.

  • 5-advjvg.zip