Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Comp 401 Assignment 2: Object Scanning Words and Numbers, Assignments of Computer Science

An assignment for a java programming course where students are required to write a class that defines two properties: input (a string) and tokenarray (a string array). The input property is editable, while tokenarray is a computed property that stores words and numbers found in the input string. Students are expected to use character.isdigit(), character.isletter(), substring(), length(), and charat() functions for this assignment. The document also provides instructions for testing the class using two main programs and objecteditor.

Typology: Assignments

Pre 2010

Uploaded on 03/16/2009

koofers-user-0om
koofers-user-0om 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Comp 401 ‐ Assignment 2:
Object Scanning Numbers and Words
Date Assigned: Thu Jan 22, 2009
Completion Date: Thu Jan 29, 2009
Early Submission Date: Tue Jan 27, 2009
In this assignment, you will get more practice scanning. In addition, you will learn instance
variables, properties and class instantiation. This work will build on your previous assignment.
Task
Write a class that defines two properties: (1) Input of type String, and (2) TokenArray, of type
String[]. You can assume a maximum size , MAX_TOKENS, for TokenArrray. Input is an editable
property and TokenArray is a readonly computed property. Input is expected to contain digit
sequences (numbers) and letter sequences (words). You can assume that there:
1. is exactly one space character after each number/word (including the last one).
2. is at least one number/word in Input.
3. are never more than MAX_TOKEN numbers/words in Input.
4. are no errors.
Your task is to scan Input for the words and numbers and store them in
TokenArray. More specifically, if you find N words and numbers in the string, then you
should store them in the first N slots of the array. 1. You should not convert a digit
sequence into a number for this assignment – you should store it directly as a string.
You should write two main programs to test this class. One takes a string
argument, prints it, and then uses an instance of this class to set Input and then print all
the elements of TokenArray. The other takes no string argument, and user ObjectEditor
to interact with an instance of the class. The following screen shots from ObjectEditor
illustrate the interaction with the object.
pf3
pf4

Partial preview of the text

Download Comp 401 Assignment 2: Object Scanning Words and Numbers and more Assignments Computer Science in PDF only on Docsity!

Comp 401 ‐ Assignment 2:

Object Scanning Numbers and Words

Date Assigned: Thu Jan 22, 2009

Completion Date: Thu Jan 29, 2009

Early Submission Date: Tue Jan 27, 2009

In this assignment, you will get more practice scanning. In addition, you will learn instance variables, properties and class instantiation. This work will build on your previous assignment.

Task Write a class that defines two properties: (1) Input of type String, and (2) TokenArray , of type String[]. You can assume a maximum size , MAX_TOKENS, for TokenArrray. Input is an editable property and TokenArray is a readonly computed property. Input is expected to contain digit sequences (numbers) and letter sequences (words). You can assume that there:

  1. is exactly one space character after each number/word (including the last one).
  2. is at least one number/word in Input.
  3. are never more than MAX_TOKEN numbers/words in Input.
  4. are no errors.

Your task is to scan Input for the words and numbers and store them in TokenArray. More specifically, if you find N words and numbers in the string, then you should store them in the first N slots of the array. 1. You should not convert a digit sequence into a number for this assignment – you should store it directly as a string.

You should write two main programs to test this class. One takes a string argument, prints it, and then uses an instance of this class to set Input and then print all the elements of TokenArray. The other takes no string argument, and user ObjectEditor to interact with an instance of the class. The following screen shots from ObjectEditor illustrate the interaction with the object.

(a) Initial Display (b) User edits Input and presses Enter

(c) User Re‐edits and presses Enter

Figure 1 ObjectEditor Interaction

There are two parts to this assignment. The first is to recognize words in addition to numbers. The second is put the scanner code into a class with the two properties. It may be best to do the assignment in two parts. First, change the last assignment to recognize and print words and numbers. Next, create an instantiatable class with the required properties. Let me know ASAP if ObjectEditor creates problems – that is does not display or set a property value correctly.

Your displays might not be identical to the ones I show in the assignment handout even when you use the same examples. The difference may be caused by different versions of ObjectEditor (I am using the latest version) and initial values. The displays and initial values do not matter, anything is acceptable. What matters is that you implement and update the properties correctly.

program, and interaction with ObjectEditor for the second main program. To print a window, do the following. Click on a window and then press Alt and PrtSc keys together. This will copy the image to a buffer. You can now paste the buffer in a document.

  1. Upload the assignment directory in blackboard. In general, for all assignments, you should do so by midnight of the day the assignment is due. But do not change the code after you submit it in class.

Good luck!