15 Aug Hw8
1. (10 points) Chapter 8: Self-check problems #7, #11, #15, #19, #26, #27.
If you use 2nd edition: Self-check problems #7, #10, #13, #16, #23 and #24.
For your benefit, I suggest you complete all of the self-check problems on your own. However, I will just collect the answers to the above six problems. Please type the answers into a document.
a. NO NEED to copy original questions, just put down the question number and the answer. b. Name the file as “LastnameFirstname8.doc” (or “.docx” or “.pdf”, where “Lastname” is
your last name, and “Firstname” is your first name), submit it online.
2. (40 points) Chapter 8: Programming Project #1 “Rational Number” a. Download the attached “RationalNumber.java”
b. Background: a rational number represents a fraction, e.g. 3 / 5. Here, 3 is the numerator,
and 5 is the denominator; both are integers (can be either positive or negative). The
denominator cannot be 0.
c. Implement two constructors:
public RationalNumber(int numerator, int denominator)
It constructs a new rational number. You can assume that the denominator will never be 0.
public RationalNumber()
It constructs a new rational number to represent 0 / 1
d. Implement the two accessors:
public int getDenominator()
It returns this rational number’s denominator. For example, for 3 / 5, it returns 5.
public int getNumerator()
It returns this rational number’s numerator. For example, for 3 / 5, it returns 3.
e. Implement the toString method:
public String toString()
It returns a String representation of this rational number, such as “3/5”.
If the denominator is 1, omit it. For example, for 4 / 1, it returns “4”.
If the numerator is 0, omit denominator. For example, for 0 / 8, it returns “0”.
CS 210 W. Li Assignment 8
You do NOT need to worry about reduced form (e.g. for 3 / 6, just returns “3/6” is good
enough, no need to return “1/2”), or negative numbers (e.g. for 3 / -5, just returns “3/-5”
is enough, no need to return “-3/5”).
f. Implement the methods to add, subtract, multiply and divide another rational number.
Here is the “method signature” for add:
public RationalNumber add(RationalNumber numberToAdd)
In the method, you should compute and return the result for the addition. For example,
if r1 is 3 / 5, r2 is -1 / 5, r1.add(r2) should return a value of 2 / 5.
Whether you choose to update the value of r1 is your choice — in other words, it won’t
affect your grade, as long as the value returned from the method is correct.
Again, you don’t need to worry about reduced form.
Please make sure NOT to change the “method signatures” in the original file,
otherwise you will receive significant penalty.
g. For this assignment, you are limited to the language features in Chapters 1 through 8 of
the textbook.
h. Remember, your program will be graded both on “external correctness” and “internal
design and style” (whether your source code follows the style guide)
i. Submit the final “RationalNumber.java” file (DO NOT change the file name)
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
