Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Solutions Manual for Data Structures and Algorithms in Java, 6e Michael Goodrich, Roberto Tamassia (All Chapters)

Rating
-
Sold
-
Pages
126
Grade
A+
Uploaded on
17-06-2026
Written in
2025/2026

Solutions Manual for Data Structures and Algorithms in Java, 6e Michael Goodrich, Roberto Tamassia (All Chapters)

Institution
Data Structures And Algorithms In Java, 6e
Course
Data Structures and Algorithms in Java, 6e

Content preview

Solutions Manual for
Data Structures and
Algorithms in Java, 6e
Michael Goodrich,
Roberto Tamassia (All
Chapters)

, Chapter


1 Java Primer xz




Hints and Solutions xz xz




Reinforcement
R-
1.1) Hint Use the code templates provided in the Simple Input and O
x z xz x z x z x z x z x z x z x z x z x z xz




utput section. xz




R-1.2) Hint You may read about cloning in Section 3.6.
xz xz xz xz xz xz xz xz xz




R-
1.2) Solution Since, after the clone, A[4] and B[4] are both pointing to the sa
xz xz xz xz xz xz xz xz xz xz xz xz xz xz




me GameEntryobject, B[4].scoreis now 550.
xz xz xz xz xz xz




R-1.3) Hint The modulus operator could be useful here.
xz xz xz xz xz xz xz xz




R-1.3) Solution xz




public boolean isMultiple(long n, long m) {
xz xz xz xz xz xz




return (n%m == 0); xz xz xz




}
R-1.4) Hint Use bit operations.
xz xz xz xz




R-1.4) Solution xz




public boolean isEven(int i) {
xz xz xz xz




return (i & 1 == 0); xz xz xz xz xz




}
R-
1.5) Hint The easy solution uses a loop, but there is also a formula for this,
xz xz xz xz xz xz xz xz xz xz xz xz xz xz xz xz




which is discussed in Chapter 4.
xz xz xz xz xz




R-1.5) Solution xz




public int sumToN(int n) {
xz xz xz xz




int total = 0;
xz xz xz




for (int j=1; j <= n; j++) total
xz xz xz xz xz xz xz xz




+= j; xz




return total; xz




}

,2 Chapter 1. Java Primer
xz x z xz




R-1.6) Hint The easy thing to do is to write a loop.
xz xz xz xz xz xz xz xz xz xz xz




R-1.6) Solution xz




public int sumOdd(int n) {
xz xz xz xz




int total = 0;
xz xz xz




for (int j=1; j <= n; j += 2) tot
xz xz xz xz xz xz xz xz xz




al += j;
xz xz




return total; xz




}
R-1.7) Hint The easy thing to do is to write a loop.
xz xz xz xz xz xz xz xz xz xz xz




R-1.7) Solution xz




public int sumSquares(int n) {
xz xz xz xz




int total = 0;
xz xz xz




for (int j=1; j <= n; j++) total
xz xz xz xz xz xz xz xz




+= j∗j; xz




return total; xz




}
R-1.8) Hint You might use a switch statement.
xz xz xz xz xz xz xz




R-1.8) Solution xz




public int numVowels(String text) {
xz xz xz xz




int total = 0;
xz xz xz




for (int j=0; j < text.length(); j++) {
xz xz xz xz xz xz xz




switch (text.charAt(j)) { xz xz




case 'a': xz




case 'A': xz




case 'e': xz




case 'E': xz




case 'i': xz




case 'I': xz




case 'o': xz




case 'O': xz




case 'u': xz




case 'U': tota xz xz




l+=1; zx xz




}
}
return total; xz




}
R-1.9) Hint Consider each character one at a time.
xz xz xz xz xz xz xz xz

, 3
R-1.10) Hint Consider using get and set methods for accessing and mod-
xz xz xz xz xz xz xz xz xz xz xz




ifying the values.
xz xz xz




R-
1.11) Hint The traditional way to do this is to use setFoo methods, wh
x z xz xz x z x z x z x z x z x z xz x z x z xz




ere Foo is the value to be modified.
xz xz xz xz xz xz xz




R-1.11) Solution xz




public void setLimit(int lim) { xz xz xz xz




limit = lim; xz xz




}
R-1.12) Hint Use a conditional statement. xz xz xz xz xz




R-1.12) Solution xz




public void makePayment(double amount) { xz xz xz xz




if (amount > 0) balance
xz xz xz xz




−= amount; xz xz




}

R-1.13) Hint Try to make wallet[1] go over its limit.
xz xz xz xz xz xz xz xz xz




R-1.13) Solution xz




for (int val=1; val <= 58; val++) { wallet[0].c
xz xz xz xz xz xz xz xz




harge(3∗val); wallet[1].charge(2∗val); wall xz xz




et[2].charge(val);
}
This change will cause wallet[1] to attempt to go over its limit.
xz xz xz xz xz xz xz xz xz xz xz




Creativity
C-1.14) Hint The Java method does not need to be passed the value of n
xz xz xz xz xz xz xz xz xz xz xz xz xz xz




as an argument.
xz xz




C-1.15) Hint Note that the Java program has a lot more syntax require-
xz xz xz xz xz xz xz xz xz xz xz xz




ments.
xz




C-
1.16) Hint Create an enum type of all operators, including =, and use an arr
xz xz xz xz xz xz xz xz xz xz xz xz xz xz




ay of these types in a switch statement nested inside for-
xz xz xz xz xz xz xz xz xz xz




loops to try all possibilities.
xz xz xz xz




C-
1.17) Hint Note that at least one of the numbers in the pair must be even.
xz xz xz xz xz xz xz xz xz xz xz xz xz xz xz




C-1.17) Solution xz

Written for

Institution
Data Structures and Algorithms in Java, 6e
Course
Data Structures and Algorithms in Java, 6e

Document information

Uploaded on
June 17, 2026
Number of pages
126
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$16.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
VICTORYSUCCESS Chamberlain College Of Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
15
Member since
1 year
Number of followers
0
Documents
2194
Last sold
1 month ago
victory success store

On this page, you find all documents, package deals, and flashcards offered by seller victory success

3.0

2 reviews

5
1
4
0
3
0
2
0
1
1

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions