[SOLVED] CSE110 -  Assignment #5

30.00 $

Category:

Description

5/5 - (1 vote)

Topics

  • Object Oriented Programming (Chapter 8)
    • Encapsulation
    • Implementing classes
    • Implementing methods
    • Object construction
    • Constructors
  • Methods (Chapter 5)
    • Definition and Invocation.

Use the following Guidelines:

  • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).
  • Keep identifiers to a reasonably short length.
  • User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).
  • Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
  • Use white space to make your program more readable.

 

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.

  1. Explain what this program is within 500 words. Using the keyword quiz and list up the task of each command (A, B, …)
  2. What is the quiz called, and what is the Quiz called in OOP?
  3. List up all Quiz ‘s methods/constructors invoked in the Assignment5.java. (Show the line number and name of method for each)
  4. Explain in your words why the nextLine() methods are used instead of next( )?
  5. Explain what is happened when the user type “?” command.

/*

  1. This program is to …
  2. The quiz is … , and Quiz is …
  3. XXX(XXX)at line-5, XXX(xxx, xxx)at line-100, …
  4. The nextLine() is required because …
  5. 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)
private  String

(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)
getChoice
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)       Make a random list of 4 letters, A,B,C, and D such as “BDCA”.

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