CSE logo University of Washington Department of Computer Science & Engineering
 CSE 142 Winter 2003 -- Homework #3
  UW Home     CSE Home   Message Board    Contact Info 

CSE 142
 Home page
 Syllabus
Classwork
 Calendar
 Homework
 Projects
 Exams
 Quizzes
Software & Computing
 Programming Lab Info
 Computing at Home
 Java Libraries
 Troubleshooting
Staying in Touch
 Discussion Board
 Virtual TA
 Announcement Archive
 Mailing Lists
Staff
 Instructors
 TAs
 Consultants
 Consultant Schedule
Check Your Scores
 MyUW
   

CSE 142 Homework #3

Due: Sunday, February 2 at 9:00 PM. No late assignments will be accepted.

Directions: Please answer the following questions. Use full sentences when answering questions that require explanations. Remember to acknowledge any help you receive from individuals outside the course staff. These questions are based on material from lecture and from Chapters 5 and 6 in the textbook.

You answers should be formatted using Microsoft Word or WordPad (.doc file), Notepad or any plain text editor (.txt), or any other file format that can be read by recent versions of Microsoft Word. When you are done, use this turnin form to submit this assignment along with part A of programming project 1 over the web. If you make a mistake, you can resubmit your assignment as often as needed. We will grade the last one that you hand in. Your graded assignment will be returned to you via email. Please include the questions along with your answers in your homework file.

Remember to get started right away. Don't wait until Sunday after dinner to begin, or you are likely not to finish on time.

Grading Guidelines: Unless indicated otherwise, each question or part of a question is worth 2 points. To gain the full 2 points, your answer must have no significant flaws, must be clear to the reader, and must be complete (but remember that complete does not mean verbose - be concise and to the point). One point will be awarded to answers that are partially correct, are somewhat unclear, or are incomplete. You must show credible effort to gain at least one point per question.

1. Assume i and j are variables of type int and that x and y are variables of type double. Assume i contains the value 4, j contains the value 5, x contains the value 6.0, and y contains the value 7.0. Evaluate the following Java expressions and state the type for each resulting value. [Please try to evaluate these expressions yourself. You may use the interactions window in Dr. Java to check your answers.]

i * j

i / j

j / i

x / y

x / j

i % j

12 / i + j

12 / (i + j)

- i + 4.0

i * y / 14.0

2. [11 points] Assume you have been hired by a credit card company to design the internals of their system to track credit card accounts. Your job is to design the credit card account class. Be sure the credit card account class supports the following operations:

  • Each credit card account should have a customer name associated with it
  • Each credit card account has an account identification number
  • Each credit card account has a credit limit
  • Each credit card account has a balance [the amount of money the customer owes the credit card company]
  • A credit card account can receive payments that include the payment amount to reduce the credit card balance
  • A credit card account can receive charges charges that include the charge amount as long as the resulting charge does not exceed the customer's credit limit. If the resulting charge exceeds the credit limit, this operation should return the boolean value false. If the resulting charge does not exceed the credit limit, this operation should return the boolean value true.
  • A credit card account can receive payment by charging another credit card account with the amount. The charge cannot exceed the credit limit of the charged credit card account. The balances of each account should be updated appropriately.
  • When a credit card account object is created, the constructor should set the customer name, account number, and credit limit according to the parameters given in the constructor. The constructor should also set the balance to 0.0.

[2 points] Design a credit card class by listing the properties and responsibilities of the class. For each property, give the type of that property.

[3 points] Design the specification of the class. Remember, the specification includes queries, commands, and constructors that clients may ask credit card account objects to perform.

[3 points] Design the implementation of the class and add the implementation to the specification.

[3 points] Test your implementation. Give evidence that your class works as you expect. Show that you can create multiple instances of the credit card class.

3. Assume that x, y, and z are of type int. Assume x has value 2, y has value 4, and z has value 6. Evaluate the following boolean expressions. [Please try to evaluate these expressions yourself. You may use Dr. Java to check your answers.]

x < 4

x >= 2

x > 2 || y == 4

x < 2 && y == 4

!(x > 2)

x != 3 && x != 4

(y < z && y < x) || y >= x

z / (x - 3) == 1 && y < z

4. [6 points -- 2 points per part] [Exercise 6.7] Given that x, y, and z are int variables, write statements to accomplish the following:

(a) Assign to z the larger of x and y.

(b) Assign to x the absolute value of x. [For example, the absolute value of 3 is 3 and the absolute value of -3 is 3.]

(c) Assign to z the largest of x, y, and z

5. [Exercise 6.10] Consider the class Student specified in Chapter 4 [pages 84 - 86]. Assume that fees are assessed as follows:

0 - 3 credit hours:        $500

4 - 6 credit hours:        $750

7 - 9 credit hours:        $1000

10 or more credit hours:    $1250

Based on this fee chart, write a definition of the method fees. Include the specification and implementation for this definition.

6. [Exercise 6.5] On page 143, the observation is made that the operators == and != are rarely used to compare floating point values. How might you compare floating point values for equality?

7. [Based on loops covered in lecture] Consider the following code, where i and sum are of type int.

i = 1;

sum = 0;

while (i < 10) {

    sum = sum + i;

    i = i + 1;

}

What is the final value of i?

What is the final value of sum?

What does this loop compute?

8. Please complete part A of Project 1. Use the turnin form to submit the files for part A of the project along with this assignment. (Submit the files separately; don't paste the code for the project into the file containing your solutions to this homework.) Both you and your partner should turn in the code for this homework assignment, but the code should be the same since you are working on the project together.


CSE logo Department of Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
[comments to cse142-webmaster]