Introduction Program Requirements – General Algorithm

advertisement

CSCI 1301: Introduction to Computing and Programming

Project 2: Multiple Choice Flash Cards

Summer 2015

Introduction

This project will allow you to apply your knowledge of decision statements, variables, assignments, expressions, inputs, outputs, algorithm design, compiling, testing, and debugging source code. The program can be completed using the aforementioned programming concepts with an emphasis on decision statements. Although loops are not required for you to program in this project, you may use loops or any other features of Java found in the Java 8 API. After completing this project, you’ll have your own program that will aid you in studying programming concepts.

You will write a Java application called MultipleChoiceFlashCards in a file called

MultipleChoiceFlashCards.java

. The game you’ll implement is a text-based, three round version of a multiple choice computer science flashcard game. A round of the game consists of a user being asked a multiple choice computer science question/problem, and after the user answers it, your game will decide if the answer is correct. The player starts with zero points, and gains a point for each question/problem correctly answered. At the end of the game, your program must tell the user how many points they scored out of the total possible points, and it must have consistent I/O statements as shown in the examples at the end of this project.

Furthermore, your program must use pre-generated questions from the class

MultipleChoiceFlashCardsZoeyGameEngine001 , which contains more than 100 questions .

The questions supplied to your program will be pseudorandomly returned (with four answer choices pseudorandomly shuffled) from the methods in the supplied class

MultipleChoiceFlashCardsZoeyGameEngine001 found on the labs and projects webpage in the file MultipleChoiceFlashCardsZoeyGameEngine001.jar

. You must download and use

MultipleChoiceFlashCardsZoeyGameEngine001.jar

in your Eclipse Java project. To use the

.jar (Java Archive) file, follow the instructions in the link “Adding Jar Files to Projects” on the labs and projects webpage to add it to your Eclipse Java project. Failure to use

MultipleChoiceFlashCardsZoeyGameEngine001 correctly may result in a failing grade on this project.

Program Requirements – General Algorithm

The steps below must be followed in order for full credit to be awarded. Following the instructions is a vital part to this and all programming projects. Implementation details about this algorithm are shown in the examples at the end of this document, and your program must implement these details as shown in the examples.

1.

Display the following to the user.

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

2.

Use the code below (after declaring all necessary String variables shown below) to retrieve the questionAndChoices, choices (A, B, C, and D), and the answer to the question from the

MultipleChoiceFlashCardsZoeyGameEngine001 . The instructions on the first page of this document must be followed in order to use

MultipleChoiceFlashCardsZoeyGameEngine001 . Also note that the method getQuestionAndChoices() can be called, at most, three times. After the third call to the method, the program will display an error message and exit the calling program. This project only requires this method to be called (at most) three times.

  questionAndChoices  =  MultipleChoiceFlashCardsZoeyGameEngine001.

getQuestionAndChoices ();   choiceA  =  MultipleChoiceFlashCardsZoeyGameEngine001.

getChoiceA ();   choiceB  =  MultipleChoiceFlashCardsZoeyGameEngine001.

getChoiceB ();   choiceC  =  MultipleChoiceFlashCardsZoeyGameEngine001.

getChoiceC ();   choiceD  =  MultipleChoiceFlashCardsZoeyGameEngine001.

getChoiceD ();   answer  =  MultipleChoiceFlashCardsZoeyGameEngine001.

getAnswer ();

3.

Display questionAndChoices retrieved in the previous step.

 

4.

Prompt the user with the following.

Enter  your  answer  (a-­‐d):      

5.

Retrieve the user’s answer. You may assume the user’s answer will be inputted as a single

String that contains at least one character; however, your program must determine if the answer is valid. Strings that begin with the character ‘a’, ‘A’, ‘b’, ‘B’, ‘c’, ‘C’, ‘d’, or ‘D’ are valid answers. If the answer is valid, then go to the next step. Otherwise if the answer is invalid, display the following and exit your program.

Invalid  answer.  

An  answer  must  begin  with  a,  A,  b,  B,  c,  C,  D,  or  d.  

Game  over!

6.

Determine if the user’s answer is correct or incorrect based on the first character in the user’s answer, and display the appropriate messages as shown in the examples at the end of this project.

7.

Repeat steps 2 through 6 for the second and third questions. Note: the first, second, and third questions should be different (if they are not different, then your program has a bug that needs to be fixed).

8.

Display the end of game output statements as shown in the examples at the end of this project, and note the special output messages in the table below based on the user’s final score.

User’s     final  score  

0  

1  

2  

3  

End  of  game  output  statement  

Your  computer  science  wit  needs  sharpening.  

Your  computer  science  wit  needs  sharpening.  

Your  computer  science  wit  is  sharp.  

Your  computer  science  wit  is  as  sharp  as  Occam's  razor.  

 

CSCI 1301: Project 2 Page 2

Also your program’s source code must contain the following class comment with the brackets filled in with this project’s information (class name, your name, and submission date). The class comment should be placed directly above the class declaration but under the program’s import statement(s).

/*

* [Class name here].java

* Author: [Your name here]

* Submission Date: [Submission date here]

*

* Purpose: A brief paragraph description of the

* program. What does it do?

*

* Statement of Academic Honesty:

*

* The following code represents my own work. I have neither

* received nor given inappropriate assistance. I have not copied

* or modified code from any source other than the course webpage

* or the course textbook. I recognize that any unauthorized

* assistance or plagiarism will be handled in accordance with

* the University of Georgia's Academic Honesty Policy and the

* policies of this course. I recognize that my work is based

* on an assignment created by the Department of Computer

* Science at the University of Georgia. Any publishing

* or posting of source code for this project is strictly

* prohibited unless you have written consent from the Department

* of Computer Science at the University of Georgia.

*/

Every Java file of every project you submit must have a comment such as this.

Project Submission

Submit the file MultipleChoiceFlashCards.java

and only that file via eLC.

Project Grading

All projects are graded out of a possible 100 points. Programs can be submitted up to 48 hours late, but late programs will lose 25 points on the first day late and 50 points on the second day late. Programs not submitted within 48 hours after the deadline will receive a grade of zero.

Programs that do not compile will receive a grade of zero. You must make absolutely certain your program compiles before submitting, and you must thoroughly test your program with different inputs to verify that it is working correctly. Your program must work with aforementioned .jar file; otherwise, your project may receive a failing grade. All instructions must be followed in order to receive full credit.

This project will be graded for both correctness and style:

 

CSCI 1301: Project 2 Page 3

Style [20pts]

5 points for including the class comment required for all projects.

• 5 points for helpful comments.

• 5 points for using well-named variables, conforming to Java naming conventions, and naming your submitted file correctly (spelling and case).

• 5 points for proper and consistent code indentation and readability.

Correctness [80pts]

• 80 points for correct output on various tests cases.

Examples

Your program should work correctly and follow the examples below. Each example is a separate run of a correctly working program. Please note that some long lines of output are wrapped around multiple lines in this document, and it is okay if your output displays them on a single line.

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

In  Java,  when  two  strings  join  or  connect  together  to  form  a  larger   string,  this  is  known  as?  

   A.    string  methods  

   B.    concatenation  

   C.    empty  string  

   D.    increments  

Enter  your  answer  (a-­‐d):    B  

Correct  Answer!  

Your  score:  1  out  of  1  point(s)  

 

Loops  that  know  the  number  of  loop  iterations  before  the  loop  starts   are  called  a:  

   A.    Semantic  loop  

   B.    Count-­‐controlled  loop  

   C.    Logical  loop  

   D.    Controlled  loop  

Enter  your  answer  (a-­‐d):    b  

Correct  Answer!  

Your  score:  2  out  of  2  point(s)  

 

If  x  is  0,  what  is  the  value  of  (!x  ==  0)  in  Java?  

   A.    unknown  since  the  syntax  is  invalid  

   B.    0  

   C.    true  

   D.    false  

 

CSCI 1301: Project 2 Page 4

Enter  your  answer  (a-­‐d):    a  

Correct  Answer!  

Your  score:  3  out  of  3  point(s)  

 

Your  final  score:  3  out  of  3  point(s)  

Your  computer  science  wit  is  as  sharp  as  Occam's  razor.  

Game  Over!

 

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

An  instance  of  a  class  is  called  a(n)  

   A.    object  

   B.    variable  

   C.    class  

   D.    method  

Enter  your  answer  (a-­‐d):    D  

Incorrect  Answer!  

Your  score:  0  out  of  1  point(s)  

 

In  Java  7.0,  (15  /  4)  will  evaluate  to  

   A.    3.8  

   B.    4  

   C.    3  

   D.    3.75  

Enter  your  answer  (a-­‐d):    b  

Incorrect  Answer!  

Your  score:  0  out  of  2  point(s)  

 

Which  loop  statement  will  always  perform  at  least  one  iteration?  

   A.    do-­‐while  

   B.    while  

   C.    loop  

   D.    nested  loop  

Enter  your  answer  (a-­‐d):    d  

Incorrect  Answer!  

Your  score:  0  out  of  3  point(s)  

 

Your  final  score:  0  out  of  3  point(s)  

Your  computer  science  wit  needs  sharpening.  

Game  Over!  

 

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

CSCI 1301: Project 2 Page 5

 

For  lengthy  input  lists,  a  user  can  signal  the  end  of  repetition  by   entering  a  

   A.    for-­‐loop  

   B.    count  control  

   C.    sentinel  value  

   D.    null  statement  

Enter  your  answer  (a-­‐d):    a  

Incorrect  Answer!  

Your  score:  0  out  of  1  point(s)  

 

Which  of  the  following  represent  the  mathematical  expression  1  <  2  <  3   as  a  boolean  expression  in  Java?  

   A.    (1  >  2  ||  2  >  3)  

   B.    (1  >  2  &&  2  >  3)  

   C.    (1  <  2  <  3)  

   D.    (1  <  2  &&  2  <  3)  

Enter  your  answer  (a-­‐d):    DBA  

Correct  Answer!  

Your  score:  1  out  of  2  point(s)  

 

Loops  that  know  the  number  of  loop  iterations  before  the  loop  starts   are  called  a:  

   A.    Count-­‐controlled  loop  

   B.    Semantic  loop  

   C.    Controlled  loop  

   D.    Logical  loop  

Enter  your  answer  (a-­‐d):    c  

Incorrect  Answer!  

Your  score:  1  out  of  3  point(s)  

 

Your  final  score:  1  out  of  3  point(s)  

Your  computer  science  wit  needs  sharpening.  

Game  Over!

 

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

An  error  that  is  detected  when  your  program  is  executing  is  called   a(n)?  

   A.    compiling  error  

   B.    testing  error  

   C.    operation  error  

   D.    run-­‐time  error  

Enter  your  answer  (a-­‐d):    d  

 

CSCI 1301: Project 2 Page 6

Correct  Answer!  

Your  score:  1  out  of  1  point(s)  

 

Variables  and  values  that  are  part  of  an  expression  in  Java  are   typically  called?  

   A.    operands  

   B.    characters  

   C.    operators  

   D.    constants  

Enter  your  answer  (a-­‐d):    b  

Incorrect  Answer!  

Your  score:  1  out  of  2  point(s)  

 

What  is  a  program  that  alternates  the  translation  and  execution  of   statements  in  a  program  written  in  a  high-­‐level  language?  

   A.    compiler  

   B.    interpreter  

   C.    RAM  

   D.    JVM  

Enter  your  answer  (a-­‐d):    b  

Correct  Answer!  

Your  score:  2  out  of  3  point(s)  

 

Your  final  score:  2  out  of  3  point(s)  

Your  computer  science  wit  is  sharp.  

Game  Over!

 

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

Which  of  the  following  signed,  8-­‐bit,  binary  number  is  equal  to  22  

(base-­‐10)?  

   A.    00100010  

   B.    10010110  

   C.    00001101  

   D.    00010110  

Enter  your  answer  (a-­‐d):    Delta  

Correct  Answer!  

Your  score:  1  out  of  1  point(s)  

 

What  is  the  correct  Java  notation  for  "Not  equal  to"?  

   A.    ||  

   B.    !=  

   C.    ?=  

   D.    /=  

 

CSCI 1301: Project 2 Page 7

Enter  your  answer  (a-­‐d):    Beta  

Correct  Answer!  

Your  score:  2  out  of  2  point(s)  

 

==  is  useful  for  determining  if  two  values  are  the  same  for  all  of  the   following  except...  

   A.    int  

   B.    char  

   C.    boolean  

   D.    String  

Enter  your  answer  (a-­‐d):    D  

Correct  Answer!  

Your  score:  3  out  of  3  point(s)  

 

Your  final  score:  3  out  of  3  point(s)  

Your  computer  science  wit  is  as  sharp  as  Occam's  razor.  

Game  Over!

 

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

Which  of  the  following  is  the  exit  method?  

   A.    Scanner.exit(0);  

   B.    System.exit(0);  

   C.    System.out(0);  

   D.    System.terminate(0);  

Enter  your  answer  (a-­‐d):    System.exit(0);  

Invalid  answer.  

An  answer  must  begin  with  a,  A,  b,  B,  c,  C,  D,  or  d.  

Game  over!  

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

How  much  memory  does  the  primitive  type  double  use?  

   A.    2  bytes  

   B.    1  byte  

   C.    8  bytes  

   D.    4  bytes  

Enter  your  answer  (a-­‐d):    a  

Incorrect  Answer!  

Your  score:  0  out  of  1  point(s)  

 

What  is  ordinal  value  of  Suit.SPADES  in  the  following  enumeration?  

     enum  Suit{HEARTS,  DIAMONDS,  SPADES,  CLUBS}  

 

CSCI 1301: Project 2 Page 8

   A.    1  

   B.    4  

   C.    2  

   D.    3  

Enter  your  answer  (a-­‐d):    b  

Incorrect  Answer!  

Your  score:  0  out  of  2  point(s)  

 

How  would  a  constant  of  type  char  be  written?  

   A.    Placing  the  character  between  two  semi-­‐colons  

   B.    Placing  the  character  between  two  single  quotes  

   C.    Placing  the  character  between  two  double  quotes  

   D.    Placing  the  character  between  two  colons  

Enter  your  answer  (a-­‐d):    -­‐5  

Invalid  answer.  

An  answer  must  begin  with  a,  A,  b,  B,  c,  C,  D,  or  d.  

Game  over!

 

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

Welcome  to  CSCI  1301  Multiple  Choice  Flash  Cards!  

 

Which  statement  is  true?  

   A.    A  class  is  an  instance  of  an  object.  

   B.    Auxiliary  memory  is  usually  volatile.  

   C.    A  .java  file  typically  contains  Java  source  code.  

   D.    A  .class  file  typically  contains  a  Java  program  that  can  be   executed  by  a  CPU.  

Enter  your  answer  (a-­‐d):    b  

Incorrect  Answer!  

Your  score:  0  out  of  1  point(s)  

 

For  lengthy  input  lists,  a  user  can  signal  the  end  of  repetition  by   entering  a  

   A.    sentinel  value  

   B.    count  control  

   C.    null  statement  

   D.    for-­‐loop  

Enter  your  answer  (a-­‐d):    q  

Invalid  answer.  

An  answer  must  begin  with  a,  A,  b,  B,  c,  C,  D,  or  d.  

Game  over!  

 

-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

 

CSCI 1301: Project 2 Page 9

Download