ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 29 Apr 2017 My Price 9.00

CMPS 11 Quiz4

Please explain how to get the answers to the following PDF document provided

 

 

Name _______________________
CMPS 11 Quiz4
This is a closed notes, closed book exam.
1. May 22, 2013 Ok to leave out What does the following program print?
class ClassOne {
String data = "go";
public String get() {
return data;
}
public String mystery() {
return get()+" team";
}
}
class ClassTwo extends ClassOne {
String other = "home";
public String get() {
return other;
}
} class OneTwoTest {
public static void main(String args) {
ClassOne one = new ClassOne();
ClassTwo two = new ClassTwo();
fiddle(one);
fiddle(two);
}
static void fiddle(ClassOne x) {
System.out.println(x.mystery());
}
} __________________________________
__________________________________
2. Write a method, rangeBuilder(), that takes two integer parameters m and n. The method should create an array of
integers with n-m+1 elements. You may assume that n is greater than m. Fill the array with the integer values m,
m+1, m+2, … n and return the filled array. For example if called with rangeBuilder(4,6), the method would return
an array of 3 elements containing 4 at index 0, 5 at index 1, and 6 at index 2. 3. Fill in the blanks so that the method longest() returns the longest word in the array, which is then printed by main.
For example if run with “java CmdArgs one two three four” the program would print “three” which is the longest
word in the arguments passed to the program. (Caution: This is not the exact same problem as done on quiz 4 from
last year which some of you may have studied, although obviously similar.)
class CmdArgs {
public static void main(String args) {
System.out.println(longest(args));
}
static String longest(String words) {
String max = "";
for (int i = 0; i < words.length; i++) {
if (words[i].length() > __________________________) {
_____________________________________________________
}
}
return ________________________________;
}
}
THERE ARE MORE QUESTIONS ON THE BACK 4. Write the Potion class needed by the following program in order to produce the output shown. Note it must work
for other types of Potion as well, such as new Potion("poison", 5). There is no need to check that the
amount of potion is greater than zero.
class PotionTest {
public static void main(String args) {
Potion potion = new Potion("healing", 10);
System.out.println(potion); // prints healing:10
potion.drink(3); // drink the specified amount of the potion
System.out.println(potion); // prints healing:7
}
} 5. What does the following program print?
class TwoD {
public static void main(String args) {
char data = {{'t', 'e', 's', 't'},{'i', 'n', 'g', '!'}};
printMystery(data);
}
static void printMystery(char pic) {
for (int row = pic.length-1; row >= 0; row--) {
for (int col = pic[row].length-1; col >= 0; col--) {
System.out.print(pic[row][col]);
}
System.out.println();
}
}
}

Attachments:

Answers

(11)
Status NEW Posted 29 Apr 2017 06:04 AM My Price 9.00

-----------

Attachments

file 1493449992-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)