1
CSSE 120 – Fundamentals of Software Development I
Exam 1: Fall term 2003-2004
Your name: _______________________________________ Box #: _________ Section: 1 2 3
Instructions: This exam is open book, notes, computer. In addition:
You may use the network ONLY to access the CSSE 120 web site (and items to which it links).
You must NOT use ANY forms of communication. No email, no chat, not anything!
Disable all chat tools (IM, ICQ, etc) before the exam starts!
Although the test is designed to be completed in about 1 hour, you have 2 hours to complete it.
All code you write should be correct, efficient, and use good style. However, due to time constraints, no
documentation is required.
For the paper-and-pencil part of this test, write all answers on these pages. Use the back as necessary. For the
computer part of this test, follow the instructions given there.
Problem
1.
2.
3.
4.
5.
6.
7.
8a.
8b.
Total
Points available
10
10
10
10
10
10
10
15
15
100
Your score
1.
(10 points: Each part is 1 point). For each of the following expressions, what does it produce?
NOTE: You are not allowed to use the computer for this problem
Expression
Value
(a) "Are you" + "there" + "there"
(b) "
Where are you today
".trim()
(c)
"Weak string".length()
(d)
"What is the substring?".substring(2, 6)
(e)
"Tricky one!!!".substring(5, 10).length()
(f)
4 – 3 % 5
(g)
4 + 3 * 5 / 2
(h)
(4 == 3)
(i)
(j)
( 5.0/2.5 > 2.5 )
( true && false ) || !( true && false )
2
2.
(10 points: Each part is 2 points). Suppose the following declarations are made:
String myString;
String yourString;
boolean isHigh;
int largestLength;
double temperature;
(a)
Write a valid Java expression that computes the cube of largestLength.
(b)
Write a valid Java statement that assigns to myString the first 3 characters of yourString.
(c)
Write a valid Java expression whose value is the string containing the first 3 characters of
yourString followed by the last 5 characters of myString.
(d)
Write valid sequence of Java statements that assigns true to the boolean isHigh if the value of
temperature is greater than 90.
(e)
Write a valid Java statement or sequence of statements that assign(s) largestLength the value equal
to the larger of the lengths of two strings, myString and yourString.
3.
(10 points). Consider the declarations of two variables below and write a sequence of Java statements
that swaps the values of the two variables. For example, if x was 5 and y was 10, then after this sequence of
statements, x will be 10 and y will be 5. (Note: Your code must work for any initial values of x and y, not just
for 5 and 10.)
int x;
int y;
3
4.
(10 points). Consider the following piece of code shown in the leftmost column.
In the right columns, place an X in the other columns in each place where the word at the top of its column
describes something that is in the first item in its row. DO NOT place any other X's. For example, since there
are no interfaces in the line 11. public String getSimple() {, you should not place an X in the interface column
for that row. To earn full credit, you must have X's in all of the correct places and in no incorrect places.
Constru
ctor
1.
Method
Definitio
n
Method
Call
Interface
Field
Paramet
ers
public
1
class W
2.
2
extends X
3.
3
implements Y,Z {
4.
4 private String s;
5.
public W() {
6.
this.s = "???" ;
7.
}
8.
public W(String x) {
9.
this.s = x;
10.
}
11.
public String getSimple() {
12.
return this.s;
13.
}
14.
public String getHello(String a) {
15.
16.
return this.s + " Hello " + a;
}
17. }
5.
(10 points). Consider a method called doubler that is part of a class BouncingBall. The class
contains the coordinates of the ball at any time, stored in fields of type double named x and y, while the field
max (of type double) stores the maximum allowed value for both these fields. The method doubler doubles
the value of the coordinate whose absolute value is the lesser of the two, unless the doubled value exceeds
another variable max; then it sets the value to one-third of the original value.
4
6.
(10 points). Consider banner web registration system that you used to register for your courses last
month. Briefly answer the 4 key questions for designing computational communities for this community. Limit
your answer to 4 key questions to the following space.
What is the desired behavior?
Identify any 4 entities which interact to produce this behavior?
Specify how one of these entities works? (What goes inside each entity?)
Pick one entity that interacts with another entity and describe the interaction
7.
(10 points). Consider a class Average such that any instance of that class tracks the average of the
numbers it has been presented by implementing the following interface:
interface IAverage {
void giveNumber(double d);
double getAverage();
}
Note:
(a)
If no number has been given to an instance of Average then the getAverage method returns 0.
(b)
You don’t have to keep track of every number given to the instance but you do need to keep track of
some cumulative properties of the numbers given.
5
8.
Do this problem on your computer. To do so:
Checkout the project G:\cs\csse120\exams\exam1\WordGamesExam
It is the same WordGames project that you used in class; just its name has changed.
Each of the Transformers described on the next page should extend the StringTransformer class and
implement the StringTransformable interface. Implement and test each Transformer, one by one.
If you don’t understand what the Transformer is supposed to do, ask your instructor or an assistant.
If you have any compile-time errors that you cannot resolve, you may ONCE ask for help from your
instructor. After that, you are on your own.
If you cannot get rid of compile-time errors for one (or more) of the three parts of this problem,
write down your answer to that part (or parts) of the problem on the back of the test and remove
from the WordGamesExam1 project whatever seems to be causing the compile-time errors.
When you are done, you will turn in your project electronically through CVS. Ask your instructor for help if
you have any trouble doing the copying.
Implement and test the following classes that extend the StringTransformer class and implement the
StringTransformable interface:
(a)
(15 points) Repeater: given a string, a Repeater produces a string that asks for confirmation what was
just said as in the following example. If the string given to a Repeater is "stop repeating what I
said." it produces "Did you say stop repeating what I said?".
(b)
(15 points) Multiplier: produces the product of the lengths of all the strings it has seen so far. For
example, if a Multiplier is given "Hello", then "Goodbye", then "See you later", the Multiplier first produces 5,
then 12, then 25.
Help given:
© Copyright 2026 Paperzz