|
![]() |
![]() |
![]() |
![]() |
|
![]() |
CSE 142 Homework #3Due: 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:
[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.
|