Product
variables called one,
two, and three.MUPanel
constructor method
change the name of three to "Keychain."Product
class that can be used
to change a product's name.paintComponent
method call the draw
method for each of the three Product
s.Product
objects called arrayOfProducts.Product
objects.10 Slumdog Millionaire true 22.95 MAGENTA
15 No Country for Old Men true 21.30 GREEN
20 A Beautiful Mind false 19.95 RED
25 Gladiator true 15.27 YELLOW
30 Schindler's List true 23.42 BLUE
getName
method for each product in the array and displays the names of all
products in the Java Console.Color.RED
and don't forget that for a String
or a Color
or any object to test for equality you cannot use ==
, but
must use the equals
method.) If you find at least one red
product, then display "Found" in the Java Console; otherwise display
"Not found." In any case there should be only one line of output in
the Java Console.getAveragePrice
. This method has no
parameters and returns a double
. The value to be retuned
by this method is the average price of all products in the array.MUPanel
class definition that calls the getAveragePrice
method. Like this:
System.out.println("The average price is " + getAveragePrice());
Bike
.Color
Double
Boolean
getColor
method, a setColor
method, a getPrice
method, and a setPrice
method. The setPrice
method should validate the
parameter to ensure that it is not less than 0 or greater than
1000. If the parameter is less than 0, the price
data member should be set to 0. If the parameter is greater than
1000, the price
data member should be set to 1000.toString
method that (as usual) returns
a String
describing the bike in terms of the data
members. The description must label the values returned. For example,
the return value should be formatted something like this:getSmallest
method that has two Integer
parameters and returns the smallest of the two parameter values.isLarge
method that has one Integer parameter
and returns true if the value of the parameter is greater than
500, and otherwise returns false.add100
method that has no parameters and returns
nothing. This method assumes we are in a class that has a private data
member called size
, and this method adds 100 to the
current value of size.paintComponent
method that calls the draw method of the Balloons/Flags/Whatever. We'll
ask you to sketch the output displayed in the output window, and also
to write the Java Console output. Probably, the Balloon/Flag/Whatever
class will have System.out.println stuff in the constructor, and in the
draw methods, so read carefully and trace each step as you go.Integer num = 400; System.out.println( (num / 5) ); System.out.println( (num % 5) ); num = num / 4; System.out.println( (num / 5) ); System.out.println( (num % 5) ); num = num / 7 - 1; System.out.println( (num / 5) ); System.out.println( (num % 5) ); num *= 3; System.out.println( (num / 5) ); System.out.println( (num % 5) );
parameterIsAQuestion
that
accepts one String
parameter and returns a boolean
value. If the last character of the parameter is a question mark,
the method should return true; if the last character of the parameter
is any other character, the method should return false. String firstSentence = new String("Will the Final Exam be easy?"); String secondSentence = new String("Java is so much fun!"); if ( parameterIsAQuestion(firstSentence) ) { System.out.println("Here is a question: " + firstSentence); } else { System.out.println(firstSentence + " is not a question."); } if ( parameterIsAQuestion(secondSentence) ) { System.out.println("Here is a question: " + secondSentence); } else { System.out.println(secondSentence + " is not a question."); }
parameterContainsAnInternalSpace
that
accepts one String
parameter and returns a Boolean
value. If any character in the parameter is a space OTHER THAN the first
or last character,
the method should return true; if the parameter does not contain a space in any
position OTHER THAN the first or last positions, the method should return false. String firstSentence = new String("Better study for all of your Final Exams"); String secondSentence = new String(" ThisOneWillTestAsFalse "); if ( parameterContainsAnInternalSpace(firstSentence) ) { System.out.println("There is an internal space in: " + firstSentence); } else { System.out.println(firstSentence + " has no internal spaces."); } if ( parameterContainsAnInternalSpace(secondSentence) ) { System.out.println("There is an internal space in: " + secondSentence); } else { System.out.println(secondSentence + " has no internal spaces."); }
String str = new String("If April showers bring May flowers, we'll have many flowers this year!"); System.out.println( str.length() ); System.out.println( str.charAt(4) ); System.out.println( str.substring(3, 6) ); System.out.println( str.substring(47) ); System.out.println( str.indexOf("low") ); System.out.println( str.lastIndexOf("low") ); System.out.println( str.split("s").length );