Building Java Programs 3rd Edition Reges Test Bank PDF Download
Building Java Programs 3rd Edition Reges Test Bank PDF Download
https://testbankfan.com/product/building-java-programs-3rd-edition-
reges-test-bank/
https://testbankfan.com/product/building-java-programs-a-back-to-
basics-approach-4th-edition-reges-test-bank/
https://testbankfan.com/product/building-java-programs-a-back-to-
basics-approach-4th-edition-reges-solutions-manual/
https://testbankfan.com/product/juvenile-justice-policies-programs-
and-practices-3rd-edition-taylor-test-bank/
https://testbankfan.com/product/marketing-of-high-technology-products-
and-innovations-3rd-edition-mohr-solutions-manual/
JavaScript The Web Warrior Series 6th Edition Vodnik
Solutions Manual
https://testbankfan.com/product/javascript-the-web-warrior-series-6th-
edition-vodnik-solutions-manual/
https://testbankfan.com/product/american-government-14th-edition-
ansolabehere-test-bank/
https://testbankfan.com/product/strategic-management-concepts-and-
cases-competitiveness-and-globalization-12th-edition-hitt-solutions-
manual/
https://testbankfan.com/product/criminology-today-an-integrative-
introduction-6th-edition-schmalleger-test-bank/
https://testbankfan.com/product/western-civilization-8th-edition-
spielvogel-test-bank/
Understanding Pharmacology Essentials for Medication
Safety 1st edition Workman Test Bank
https://testbankfan.com/product/understanding-pharmacology-essentials-
for-medication-safety-1st-edition-workman-test-bank/
Sample Final Exam #8
(Summer 2009; thanks to Victoria Kirst)
1. Array Mystery
Consider the following method:
public static void arrayMystery(int[] a) {
for (int i = 1; i < a.length - 1; i++) {
a[i] = a[i + 1] + a[i - 1];
}
}
Indicate in the right-hand column what values would be stored in the array after the method arrayMystery executes
if the integer array in the left-hand column is passed as a parameter to it.
Original Contents of Array Final Contents of Array
int[] a1 = {3, 7};
arrayMystery(a1); _____________________________
1 of 8
2. Reference Semantics Mystery
(Missing; we didn't give this type of question that quarter.)
3. Inheritance Mystery
Assume that the following classes have been defined:
public class Denny extends John { public class Michelle extends John {
public void method1() { public void method1() {
System.out.print("denny 1 "); System.out.print("michelle 1 ");
} }
}
public String toString() {
return "denny " + super.toString(); public class John extends Cass {
} public void method2() {
} method1();
System.out.print("john 2 ");
public class Cass { }
public void method1() {
System.out.print("cass 1 "); public String toString() {
} return "john";
}
public void method2() { }
System.out.print("cass 2 ");
}
Given the classes above, what output is produced by the following code?
Cass[] elements = {new Cass(), new Denny(), new John(), new Michelle()};
for (int i = 0; i < elements.length; i++) {
elements[i].method1();
System.out.println();
elements[i].method2();
System.out.println();
System.out.println(elements[i]);
System.out.println();
}
2 of 8
4. File Processing
Write a static method called runningSum that accepts as a parameter a Scanner holding a sequence of real numbers
and that outputs the running sum of the numbers followed by the maximum running sum. In other words, the nth
number that you report should be the sum of the first n numbers in the Scanner and the maximum that you report
should be the largest such value that you report. For example if the Scanner contains the following data:
3.25 4.5 -8.25 7.25 3.5 4.25 -6.5 5.25
3 of 8
5. File Processing
Write a static method named plusScores that accepts as a parameter a Scanner containing a series of lines that
represent student records. Each student record takes up two lines of input. The first line has the student's name and
the second line has a series of plus and minus characters. Below is a sample input:
Kane, Erica
--+-+
Chandler, Adam
++-+
Martin, Jake
+++++++
Dillon, Amanda
++-++-+-
The number of plus/minus characters will vary, but you may assume that at least one such character appears and that
no other characters appear on the second line of each pair. For each student you should produce a line of output with
the student's name followed by a colon followed by the percent of plus characters. For example, if the input above is
stored in a Scanner called input, the call of plusScores(input); should produce the following output:
Kane, Erica: 40.0% plus
Chandler, Adam: 75.0% plus
Martin, Jake: 100.0% plus
Dillon, Amanda: 62.5% plus
4 of 8
6. Array Programming
Write a method priceIsRight that accepts an array of integers bids and an integer price as parameters. The method
returns the element in the bids array that is closest in value to price without being larger than price. For example, if
bids stores the elements {200, 300, 250, 999, 40}, then priceIsRight(bids, 280) should return 250,
since 250 is the bid closest to 280 without going over 280. If all bids are larger than price, then your method should
return -1.
The following table shows some calls to your method and their expected results:
Arrays Returned Value
int[] a1 = {900, 885, 989, 1}; priceIsRight(a1, 880) returns 1
int[] a2 = {200}; priceIsRight(a2, 320) returns 200
int[] a3 = {500, 300, 241, 99, 501}; priceIsRight(a3, 50) returns -1
int[] a2 = {200}; priceIsRight(a2, 120) returns -1
You may assume there is at least 1 element in the array, and you may assume that the price and the values in bids will
all be greater than or equal to 1. Do not modify the contents of the array passed to your method as a parameter.
5 of 8
7. Array Programming
Write a static method named compress that accepts an array of integers a1 as a parameter and returns a new array
that contains only the unique values of a1. The values in the new array should be ordered in the same order they
originally appeared in. For example, if a1 stores the elements {10, 10, 9, 4, 10, 4, 9, 17}, then
compress(a1) should return a new array with elements {10, 9, 4, 17}.
The following table shows some calls to your method and their expected results:
Array Returned Value
int[] a1 = {5, 2, 5, 3, 2, 5}; compress(a1) returns {5, 2, 3}
int[] a2 = {-2, -12, 8, 8, 2, 12}; compress(a2) returns {-2, -12, 8, 2, 12}
int[] a3 = {4, 17, 0, 32, -3, 0, 0}; compress(a3) returns {4, 17, 0, 32, -3}
int[] a4 = {-2, -5, 0, 5, -92, -2, 0, 43}; compress(a4) returns {-2, -5, 0, 5, -92, 43}
int[] a5 = {1, 2, 3, 4, 5}; compress(a5) returns {1, 2, 3, 4, 5}
int[] a6 = {5, 5, 5, 5, 5, 5}; compress(a6) returns {5}
int[] a7 = {}; compress(a7) returns {}
Do not modify the contents of the array passed to your method as a parameter.
6 of 8
8. Critters
Write a class Caterpillar that extends the Critter class from our assignment, along with its movement behavior.
Caterpillars move in an increasing NESW square pattern: 1 move north, 1 move east, 1 move west, 1 move south,
then 2 moves north, 2 moves east, etc., the square pattern growing larger and larger indefinitely. If a Caterpillar
runs into a piece of food, the Caterpillar eats the food and immediately restarts the NESW pattern. The size of the
Caterpillar’s movement is also reset back to 1 move in each direction again, and the increasing square pattern
continues as before until another piece of food is encountered.
Here is a sample movement pattern of a Caterpillar:
• north 1 time, east 1 time, south 1 time, west 1 time
• north 2 times, east 2 times, south 2 times, west 2 times
• north 3 times, east 3 times, south 3 times, west 3 times
• (runs into food)
• north 1 time, east 1 time, south 1 time, west 1 time
• north 2 times, east 1 time
• (runs into food)
• north 1 time
• (runs into food)
• north 1 time, east 1 time, south 1 time, west 1 time
• north 2 times, east 2 times, south 2 times, west 2 times
• (etc.)
Write your complete Caterpillar class below. All other aspects of Caterpillar besides eating and movement
behavior use the default critter behavior. You may add anything needed to your class (fields, constructors, etc.) to
implement this behavior appropriately.
7 of 8
9. Classes and Objects
Suppose that you are provided with a pre-written class Date as // Each Date object stores a single
described at right. (The headings are shown, but not the method // month/day such as September 19.
bodies, to save space.) Assume that the fields, constructor, and // This class ignores leap years.
methods shown are already implemented. You may refer to them
or use them in solving this problem if necessary. public class Date {
private int month;
Write an instance method named subtractWeeks that will be private int day;
placed inside the Date class to become a part of each Date
object's behavior. The subtractWeeks method accepts an // Constructs a date with
integer as a parameter and shifts the date represented by the Date // the given month and day.
public Date(int m, int d)
object backward by that many weeks. A week is considered to be
exactly 7 days. You may assume the value passed is non- // Returns the date's day.
negative. Note that subtracting weeks might cause the date to public int getDay()
wrap into previous months or years.
// Returns the date's month.
For example, if the following Date is declared in client code: public int getMonth()
Date d = new Date(9, 19);
// Returns the number of days
The following calls to the subtractWeeks method would // in this date's month.
modify the Date object's state as indicated in the comments. public int daysInMonth()
Remember that Date objects do not store the year. The date
before January 1st is December 31st. Date objects also ignore // Modifies this date's state
// so that it has moved forward
leap years.
// in time by 1 day, wrapping
Date d = new Date(9, 19); // around into the next month
d.subtractWeeks(1); // d is now 9/12 // or year if necessary.
d.subtractWeeks(2); // d is now 8/29 // example: 9/19 -> 9/20
d.subtractWeeks(5); // d is now 7/25 // example: 9/30 -> 10/1
d.subtractWeeks(20); // d is now 3/7 // example: 12/31 -> 1/1
d.subtractWeeks(110); // d is now 1/26
public void nextDay()
// (2 years prior)
8 of 8
Exploring the Variety of Random
Documents with Different Content
conciliate all parties by the culture of his mind, by his learning,
wisdom, piety, and gentleness. One man, if he appears at the right
moment, is sometimes sufficient to give a new direction to an entire
epoch, to a whole nation. ‘Ah, sire,’ said Barnabas Voré de la Fosse,
a learned and zealous French nobleman, who knew Germany well,
and had tasted of the Gospel, ‘if you knew Melancthon, his
uprightness, learning, and modesty! I am his disciple, and fear not
to tell it you. Of all those who in our days have the reputation of
learning, and who deserve it, he is the foremost.’[686]
These advances were not useless: Francis I. thought the priests very
arrogant and noisy. His despotism made him incline to the side of
the pope; but his love of letters, and his disgust at the monks,
attracted him the other way. Just now he thought it possible to
satisfy both these inclinations at once. Fully occupied with the effect
of the moment, and inattentive to consequences, he passed rapidly
from one extreme to another. At Marseilles he had thrown himself
into the arms of Clement VII., now he made up his mind to hold out
his hand to Melancthon. ‘Well!’ said the king, ‘since he differs so
much from our rebels, let him come: I shall be enchanted to hear
him.’ This gave great delight to the peacemakers. ‘God has seen the
affliction of his children and heard their cries,’ exclaimed Sturm.[687]
Francis I. ordered De la Fosse to proceed to Germany to urge
Melancthon in person.
A king of France inviting a reformer to come and explain his views
was something very new. The two principal obstacles which impeded
the Reformation seemed now to be removed. The first was the
character of the reformers in France, the exclusive firmness of their
doctrines, and the strictness of their morality. Melancthon, the mild,
the wise, the tolerant, the learned scholar, was to attempt the task.
The second obstacle was the fickleness and opposition of Francis I.;
but it was this prince who made the advances. There are hours of
grace in the history of the human race, and one of those hours
seemed to have arrived. ‘God, who rules the tempests,’ exclaimed
Sturm, ‘is showing us a harbor of refuge.’[688]
Efforts Of The The friends of the Gospel and of light set
Mediators. earnestly to work. It was necessary to
persuade Melancthon, the Elector, and the protestants of Germany,
which might be a task of some difficulty. But the mediators did not
shrink from before obstacles; they raised powerful batteries; they
stretched the strings of their bow, and made a great effort to carry
the fortress. Sturm, in particular, spared no exertions. The free
courses he was giving at the Royal College, his lectures on Cicero,
his logic, which, instead of preparing his disciples (among whom was
Peter Ramus) for barren disputes, developed and adorned their
minds—nothing could stop him. Sturm was not only an enlightened
man, a humanist, appreciating the Beautiful in the productions of
genius, but he had a deep feeling of the divine grandeur of the
Gospel. Men of letters in those times, especially in Italy, were often
negative in regard to the things of God, light in their conduct,
without moral force, and consequently incapable of exercising a
salutary influence over their contemporaries. Such was not Sturm:
and while those beaux-esprits, those wits were making a useless
display of their brilliant intelligence in drawing-rooms, that eminent
man exhibited a Christian faith and life: he busied himself in the
cultivation of all that is most exalted, and during his long career,
never ceased from enlightening his contemporaries.[689] ‘The future
of French protestantism is in your hands,’ he wrote to Bucer;
‘Melancthon’s answer and yours will decide whether the evangelicals
are to enjoy liberty, or undergo the most cruel persecutions. When I
see Francis I. meditating the revival of the Church, I recognize God,
who inclines the hearts of princes. I do not doubt his sincerity; I see
no hidden designs, no political motives; although a German by birth,
I do not share my fellow-countrymen’s suspicions about him. The
king, I am convinced, wishes to do all he can to reform the Church,
and to give liberty of conscience to the French.’[690] Such was, then,
the hope of the most generous spirits—such the aim of their labors.
Sturm, wishing to do everything in his power to give France that
liberty and reformation, wrote personally to Melancthon. He was the
man to be gained, and the professor set his heart upon gaining him.
‘How delighted I am at the thought that you will come to France!’ he
said. ‘The king talks much about you; he praises your integrity,
learning, and modesty; he ranks you above all the scholars of our
time, and has declared that he is your disciple.[691] I shed tears when
I think of the devouring flames that have consumed so many noble
lives; but when I learn that the king invites you to advise with him
as to the means of extinguishing those fires, then I feel that God is
turning his eyes with love upon the souls who are threatened with
unutterable calamities. What a strange thing! France appeals to you
at the very time when our cause is so fiercely attacked. The king,
who is of a good disposition at bottom, perceives so many defects in
the old cause, and such imprudence in those who adhere to the
truth, that he applies to you to find a remedy for these evils. O
Melancthon! to see your face will be our salvation. Come into the
midst of our violent tempests, and show us the haven. A refusal
from you would keep our brethren suspended above the flames.
Trouble yourself neither about emperors nor kings: those who invite
you are men who are fighting against death. But they are not alone:
the voice of Christ, nay, the voice of God himself calls you.’[692] The
letter is dated from Paris, 4th March, 1535.
The Holy Scriptures, which were read wherever the Reform had
penetrated, had revived in men’s hearts feelings of real unity and
Christian charity. Such cries of distress could not fail to touch the
protestants of Germany; Bucer, who had also been invited, made
preparations for his departure. ‘The French, Germans, Italians,
Spaniards, and other nations, who are they?’[693] he asked. ‘All our
brethren in Jesus Christ. It is not this nation or that nation only, but
all nations that the Father has given to the Son. I am ready,’ he
wrote to Melancthon; ‘prepare for your departure.’
Importance Of What could Melancthon do? that was the
France. great question. Many persons, even in
Germany, had hoped that France would put herself at the head of
the great revival of the Church. Had not her kings, and especially
Louis XII., often resisted Rome? Had not the university of Paris been
the rival of the Vatican? Was it not a Frenchman who, cross in hand,
had roused the West to march to the conquest of Jerusalem? Many
believed that if France were transformed, all Christendom would be
transformed with her. To a certain point, Melancthon had shared
these ideas, but he was less eager than Bucer. The outspoken
language of the placards had shocked him; but the burning piles
erected in Paris had afterwards revolted him; he feared that the
king’s plans were a mere trick, and his reform a phantom.
Nevertheless, after reflecting upon the matter, he concluded that the
conquest of such a mighty nation was a thing of supreme
importance. His adhesion to the regenerating movement then
accomplishing might decide its success, just as his hostility might
destroy it. He must do something more than open his arms to
France, he must go to meet her.
Melancthon understood the position and set to work. First, he wrote
to the Bishop of Paris, in order to gain him over to the proposed
union, by representing to him that the episcopal order ought to be
maintained. The German doctor did not doubt that even under that
form, the increasing consciousness of truth and justice, the living
force of the Gospel, which was seen opening and increasing
everywhere, would gain over to the Reformation the fellow-
countrymen of St. Bernard and St. Louis. ‘France is, so to speak, the
head of the Christian world,’ he wrote to the Bishop of Paris.[694] ‘The
example of the most eminent people may exercise a great influence
over others. If France is resolved to defend energetically the existing
vices of the Church, good men of all countries will see their fondest
desires vanish. But I have better hopes; the French nation
possesses, I know, a remarkable zeal for piety.[695] All men turn their
eyes to us; all conjure us, not only by their words, but by their tears,
to prevent sound learning from being stifled, and Christ’s glory from
being buried.’
On the same day, 9th of May, 1535, Melancthon wrote to Sturm: ‘I
will not suffer myself to be prevented either by domestic ties or the
fear of danger. There is no human grandeur which I can prefer to
the glory of Christ. Only one thought checks me: I doubt of my
ability to do any good; I fear it will be impossible to obtain from the
king what I consider necessary to the glory of the Lord and the
peace of France.[696] If you can dispel these apprehensions, I shall
hasten to France, and no prison shall affright me. We must seek only
for what is fitting for the Church and France. You know that
kingdom. Speak. If you think I should do well to undertake the
journey, I will start.’
Melancthon’s letter to the Bishop of Paris was not without effect.
That prelate had just been made a cardinal; but the new dignity in
nowise diminished his desire for the restoration of truth and unity in
the Church; on the contrary, it gave him more power to realize the
great project. The Reformation was approaching. Delighted with the
sentiments expressed to him by the master of Germany, he
communicated his letter to such as might feel an interest in it, and
among others, no doubt, to the king. ‘There is not one of our friends
here,’ he said, ‘to whom Melancthon’s mode of seeing things is not
agreeable. As for myself, it is pleasant far beyond what I can
express.’[697] It was the same with his brother William. While the new
cardinal especially desired a union with Melancthon in the hope of
obtaining a wise and pious reform, the councillor of Francis I.
desired, while leaving to the pope his spiritual authority, to make
France politically independent of Rome. The two brothers united in
entreating the king to send for Luther’s friend. De la Fosse joined
them, and all the friends of peace, in conjuring the king to give the
German doctor some proof of his good-will. ‘He will come if you
write to him,’ they said.
Letter Of The King. Francis I. made up his mind, and instead of
addressing the sovereign whose subject
Melancthon was, the proud king of France wrote to the plain doctor
of Wittemberg. This was not quite regular; had the monarch written
to the elector, such a step might have produced very beneficial
results; not so much because the susceptibility of the latter prince
would not have been wounded, as because the reasons which
Francis, with Du Bellay’s help, might have given him, would perhaps
have convinced a ruler so friendly to the Gospel and to peace as
John Frederick. It is sometimes useful to observe the rules of
diplomacy. This is the letter from the King of France to the learned
doctor, dated 23d of June, 1535.
testbankfan.com