Assignment 7 on Introduction to Computing Using Java | CS 1110, Assignments of Computer Science

Material Type: Assignment; Professor: Gries; Class: Introduction to Computing Using Java; Subject: Computer Science; University: Cornell University; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 08/30/2009

koofers-user-523
koofers-user-523 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Where this assignment came from
The first programming course in computer science at the University of Toronto had a similar assignment last fall;
we took the idea and much of the text below from it. Thanks, Paul Gries, for your help! Their assignment does not
have a GUI and is done using Python instead of Java.
Partners. You may work with one partner. Both of you should do what is necessary on the CMS to form a group
several days before the submission deadline. It is dishonest and against academic integrity to split the work so that
each does half of the work. You must work together.
Time spent. When you submit the program, we will ask you how much time you spent. Please keep track of this.
Overview. This assignment is quite different in nature from the previous ones. There is a fairly large program to
complete, with more freedom in what you do than in other assignments. The assignment is designed to give you
practice in the following areas:
Program design Arrays and Vectors String manipulation
In our solution class Item is about 120 lines long and class Quizit is about 262 lines long —some of which is
given to you to start with. Quizit has about 10 methods, including the ones in the skeleton that we give you.
Check out the FAQs. The announcement table on the course website and the assignment webpage, contain a link to
a page with many frequently asked questions about this assignment. Read through the questions and answers.
Quizit. It's almost time for that animal bio quiz. Or was it the bridge
architecture quiz? Either way, it's time to procrastinate and write a
program to help you study. Your program will show a picture like the
one on the right, but with numbers (e.g. 1) instead of terms (e.g.
"liver"), and the player will try to match up terms on the picture.
Thus, the program you write will interact with the user —a player—
just like in a game.
The player is given a list of topics (each with a picture) to choose
from. The player chooses a topic, and the GUI shows the picture with
numbers as labels to various parts of the picture. The player can pick
one of the numbers and guess the real term associated with the picture
part for that number. After each guess, the GUI provides feedback about
whether the guess was right or wrong.
The assignment webpage for the course contains a link sample
game.html to a series of screenshots of this game being played. Read that page carefully before you read any further!
You can play the game on the web, because we have made an applet of it. Access it from the assignments page of
the course website.
Downloading files. From the course website, download file Quizit.zip and unzip it. It contains files Quizit.java,
Item.java, A7GUI.java, A7Panel.java (which make up the program skeleton that we give you); two images files,
shark.jpg and 076monkey.jpg; and file topics.txt, which contains the data that the program will read in. Put all files
in a directory, open the .java files in DrJava, and compile.
Input to the program. File topics.txt, located in the same directory as your program, contains the information used
by the program to draw lines and labels. This is only an example of the input. The file could contain information for
dozens of topics. The file contains no blank lines and has the following structure:
topic. topic-name file-name1
term1# x1 y1 x2 y2
term2# x1 y1 x2 y2
term3# x1 y1 x2 y2
...
topic. topic-name file-name1
term1# x1 y1 x2 y2
A7. QUIZIT CS1110 Spring 2009 Due date on the CMS 1
pf3
pf4
pf5

Partial preview of the text

Download Assignment 7 on Introduction to Computing Using Java | CS 1110 and more Assignments Computer Science in PDF only on Docsity!

Where this assignment came from The first programming course in computer science at the University of Toronto had a similar assignment last fall; we took the idea and much of the text below from it. Thanks, Paul Gries, for your help! Their assignment does not have a GUI and is done using Python instead of Java. Partners. You may work with one partner. Both of you should do what is necessary on the CMS to form a group several days before the submission deadline. It is dishonest and against academic integrity to split the work so that each does half of the work. You must work together. Time spent. When you submit the program, we will ask you how much time you spent. Please keep track of this. Overview. This assignment is quite different in nature from the previous ones. There is a fairly large program to complete, with more freedom in what you do than in other assignments. The assignment is designed to give you practice in the following areas: Program design Arrays and Vectors String manipulation In our solution class Item is about 120 lines long and class Quizit is about 262 lines long —some of which is given to you to start with. Quizit has about 10 methods, including the ones in the skeleton that we give you. Check out the FAQs. The announcement table on the course website and the assignment webpage, contain a link to a page with many frequently asked questions about this assignment. Read through the questions and answers. Quizit. It's almost time for that animal bio quiz. Or was it the bridge architecture quiz? Either way, it's time to procrastinate and write a program to help you study. Your program will show a picture like the one on the right, but with numbers (e.g. 1) instead of terms (e.g. "liver"), and the player will try to match up terms on the picture. Thus, the program you write will interact with the user —a player— just like in a game. The player is given a list of topics (each with a picture) to choose from. The player chooses a topic, and the GUI shows the picture with numbers as labels to various parts of the picture. The player can pick one of the numbers and guess the real term associated with the picture part for that number. After each guess, the GUI provides feedback about whether the guess was right or wrong. The assignment webpage for the course contains a link sample game.html to a series of screenshots of this game being played. Read that page carefully before you read any further! You can play the game on the web, because we have made an applet of it. Access it from the assignments page of the course website. Downloading files. From the course website, download file Quizit.zip and unzip it. It contains files Quizit.java, Item.java, A7GUI.java, A7Panel.java (which make up the program skeleton that we give you); two images files, shark.jpg and 076monkey.jpg; and file topics.txt, which contains the data that the program will read in. Put all files in a directory, open the .java files in DrJava, and compile. Input to the program. File topics.txt, located in the same directory as your program, contains the information used by the program to draw lines and labels. This is only an example of the input. The file could contain information for dozens of topics. The file contains no blank lines and has the following structure: topic. topic-name file-name term1# x1 y1 x2 y term2# x1 y1 x2 y term3# x1 y1 x2 y ... topic. topic-name file-name term1# x1 y1 x2 y

term2# x1 y1 x2 y ... Thus, the file is divided into "topic blocks": The first line of each block, starting with "topic.", gives the name of the topic (e.g. Shark) and the name of the file containing an image (e.g. shark.jpg). This image file should be in the directory with program. Each "term" line indicates the correct answer to a part of the image (followed by character ‘#’, which cannot be in the answer) and contains the coordinates of the lines from that point. The first pair, (x1, y1), represents the point closest to the actual picture (and thus farthest from the term); the second pair (x2, y2) is the other endpoint of the line (closest to the term). Note: Each line of the topics file begins with a non-blank. There is no blank in “topic.” and no blank between a term and the following ‘#’. Finally, one or more blanks separates the different parts of each line. For the examples in this handout, we used the files found on the course website: topics file topics.txt and image files shark.jpg. and 076monkey.jpg. Image 076monkey.jpg is a modified version of an image on website www.infovisual.info/02/076_en.html. We wrote to infovisual.info to ask for permission to use the image this way and to tell them about the assignment —the resulting program might be a neat interactive addition to their website. Their reply was that they were thinking of adding this feature to their website in 2009 and they wanted more information on how we did it. The website has hundreds of images for different topics. Overview of communication between GUI and your code in Quizit. All the code you will write goes in file Quizit.java. The program is started either by using it as an application by executing Quizit.main(null); or by visiting a webpage that has it included as an applet. We discuss applications and applets later in the course. In either case, file topics.txt is read in and stored and an instance of the GUI class is created and shown, with the topics filled in. When the player chooses a topic and clicks button topic , the GUI calls a Quizit procedure that does two things: (1) Retrieve the information for the topic from file inputFile —the topic image and the labeling information for the image— so that it can then draw the appropriate lines and numbers before displaying the image. In the next section, we discuss how this information is kept in a "dictionary" of items. (2) Call a procedure of the GUI to initialize the drop-down list of topics. When the player clicks button OK , the GUI calls a Quizit procedure to process the player's association of a number and a term. This requires two things to be done: (1) Update the item given by the number with the player's choice of a term and (2) if the choice was correct, call the GUI to remove the number and the term from the drop- down lists. Keeping track of information: a dictionary. For a topic, your program needs to keep track of the lines. To do this, use the coordinate pairs (x1,y1) and (x2,y2) found in topics.txt. Here's the spiracle (what is that ?) coordinate pair for the shark picture: (187,180) (177,131). The first point (x1,y1) is the point on the picture, not the coordinates next to the label. The lines will be drawn on the image by your program whenever the picture is displayed. For each line, your program will also maintain the correct term, the number associated with the term, and the player's guess at the term ("" if none guessed yet). We suggest that your program use class Item to contain the information for one line. We give you a skeleton for class Item. It need fields for: The points: (x1,y1) and (x2,y2), The correct term, The player's guess at this term ("" if they haven't guessed this term yet), The number of this line. The Items for the current topic can be kept in a Vector items. When a topic is chosen, a method will build this dictionary from the information that is in Vector inputFile. This dictionary should satisfy the following:

  • The items are ordered by the points (x1,y1) and x2,y2). For example, if items b and c satisfy b.x < c.x1, then item b comes before c in inputFile, and if b.x1 = c.x1 and b.y1 < c.y1, b comes before (x2,y2).

How to go about writing this program. As mentioned earlier, the code you write goes in classes Quizit and Item. Each has some code already, but basically the design and implementation is up to you. An instance of class A7GUI provides the JFrame on which everything is written, and class A7Panel, which is placed in the JFrame, is where the image for a topic is drawn. You don't have to know anything about A7GUI and A7Panel except how to use them, but we suggest you spend some time looking at them. In developing this program try to make progress in a way that allows the program to get more and more functionality, little by little, making sure that everything is correct as you go. If you don't maintain correctness of what you have done, errors will be hard to find. We give you hints on this below. When debugging, use System.out.println statements at judiciously chosen places to help you figure out what is right and wrong. You can use a JUnit testing class —which is better— but you don't have to. As you design and develop, create "helper" methods, to keep all parts of the program simple. No method should be more than 20-25 lines long, for example. If a method is getting too long, break off some functionality into another method. Be sure to put specifications on all your methods before you write their bodies! We will not be lenient in grading methods whose specifications are not precise, clear, and thorough. Steps to take in doing this assignment Play with the completed program that we make available, so that you know exactly how it works from a user's perspective. Study this handout, as well as a series of screenshots of this game being played. Then begin implementing pieces of this program until it is done, as outlined below. Do not go on to another part until you know that this part works correctly. The Quizit constructor does nothing. If this program is called using Quizit.main(null);, procedure main is called. If called from a webpage, the constructor is called and then procedure Quizit.init is called. Look at how similar main and init are. They (1) get a buffered reader for file topics.txt, (2) call method readTopicsFile to read the file into inputFile (we give you this method), and (3) create an instance of the JFrame A7GUI.

  1. Complete function fillItems. After this is written, when you do Quizit.main(null); in the DrJava interactions pane, the GUI window should open and you should be able to select topics in the drop-down topics list. Why don’t you get this done by 17 April, so that you gain confidence in your work and see that this assignment can be done?
  2. Write the body of procedure startTopic, which is called to start a new topic. In the body, we have given you hints to indicate what it should do. Proceed in small steps —we don't list all of them here but just the more important ones. Plan on getting this completed by 19 April or so.
  3. Work on class Item, putting in the necessary fields and getter/setter methods and writing function toString, so that you can use it when debugging. Write the class invariant, and put javadoc specs on all methods. Don't write everything at once, write just what you need to start building the dictionary, and complete more pieces when the need arises. FInish this by 23-24 April.
  4. You will need to write a method that retrieves the lines for the selected topic and stores the dictionary for the topic in field items. This is fairly complicated, because you need to break each line into its pieces: the term and points. Here are important points:
    • The term may consist of several words, but it ends in ‘#’.
    • The elements of field items should be sorted based on their points, as explained elsewhere. Method Item.sort can be used for this. Don't fill in the number field of the items until items has been sorted.
    • Do not proceed past this point until you are certain that this method is correct. A mistake here can be disastrous later on.
  5. Once field items is correctly constructed, you can see about placing the numbers and terms in the two drop- down menus.
  6. Finally, when the image is drawn, you are supposed to see the lines and numbers. This is the time to write function drawLinesLabels, whose purpose is to put the lines and numbers in.
  7. Write the body of associateTerm, which is called by the GUI when the player clicks button OK.

Grading Here are some general outlines and explanatory notes: Correctness : Your program should perform as specified. Correctness, as measured by our tests, will count for the largest single portion of your grade. Design and organization : While we have specified the methods that communicate between the GUI and class Quizit, and we have provided a few other methods, there is quite a lot for you to organize yourself. You will need to write several helper functions. Modularity and clarity counts. If your code is a mess, you will lose points. Commenting : Each method you write must have a suitable javadoc specification. Within methods, the more complicated parts of your code should also be described using comments. Reuse : If you find yourself repeating a task, add a helper method and call that method instead of duplicating the code. Submitting your work At the top of file Quizit.java, put a comment that gives your name(s), netid(s), and the time you spent on this assignment. Also put a comment that gives your opinion of this assignment —whether it was educational, interesting, exciting, loads of fun, too long, horribly described, how we could improve it, etc. Submit files Quizit.java and Items.java on the CMS.