Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 3, Problem 55E
Explanation of Solution
Given: The definition of class and the functions in it are given below:
//Declaration of class
public class Screen
{
//Declaration of constructor Screen
public Screen (int xRes, int yRes) { ...
}
//Declaration of function numbreOfPixels()
public int numberOfPixels() { ...
}
//Declaration of function clear()
public void clear(boolean invert) { ...
}
}
To find: The way to create the object of the Screen class and call clear() method, if the pixel count is more than 2 million.
Solution:
To create the object for the class, there are two methods:
Method I:
Right-click on the class to view the drop-down menu.
From the drop-down menu, click on compile...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
public class TwoColors
10 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
11
12
13
14
System.out.print("Enter your first favorite color: ");
15
16
// Step 2: Read in the next line of input and assign
• it to a String variable color1
17
//
18
19
// Step 3: Trim spaces from both end and convert the
//
//
20
input to all lowercase and assign it back
21
22
to the same variable
23
24
System.out.print("Enter your second favorite color: ");
25
26
// Step 4: Read in the next line of input and assign
27
//
it to a String variable color2
28
29
30
// Step 5: Trim spaces from both end and convert the
//
//
31
input to all lowercase and assign it back
32
33
to the same variable
34
35
// Step 6: Display a message according to the following:
//
36
first color
37
second color
message
light blue
38
red
That's wonderful!
light blue
39
red
That's even better!
That's also great!
40
otherwise
41
42
Java.
Tally counter that increases and decreases. Refer to screenshot.
Here is some code (class PoD):
import java.util.*;
public class PoD {
public static void main (String [] args ) {Scanner in = new Scanner( System.in );PrettyTally tally = new PrettyTally(in.next());while (in.hasNext()){String nextTask = in.next();if (nextTask.equals("increment")){tally.increment();} else if (nextTask.equals("toString")){System.out.println(tally);}else if (nextTask.equals("decrement")){tally.decrement();}}in.close();}}
Class PrettyTally:
public class PrettyTally extends TallyCounter{
}
Class TallyCounter
import java.util.*;
public class TallyCounter {
protected int count=0;public TallyCounter(){this.count = 0;} public void increment(){this.count++;}public int get(){return this.count;}}
public static void printer() {
printer("Start:");
}
public static void printer(String value) {
System.out.print(value);
printer(value + "v2", value + 3);
}
public static void printer(String v1, String v2) {
System.out.print(v1 + "," + v2);
printer(3);
}
public static void printer(double val) {
System.out.print(val / 2);
}
Given the following code, what is printed if printer("Go", "G0") is invoked?
public static void printer() {
printer("Start:");
}
public static void printer(String value) {
System.out.print(value);
printer(value + "v2", value + 3);
}
public static void printer(String v1, String v2) {
System.out.print(v1 + "," + v2);
printer(3);
}
public static void printer(double val) {
System.out.print(val / 2);
}
Answer Choices:
A. answer not listed
B. Start:Go,G01.5
C. Go,G03
D. Go,G01.5
E. Nothing - the…
Chapter 3 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Ch. 3 - Prob. 1ECh. 3 - At what time (s) can a class diagram change? How...Ch. 3 - At what time(s) can an object diagram change? How...Ch. 3 - Write a definition of a field named tutor that can...Ch. 3 - Prob. 5ECh. 3 - Create a second NumberDisplay object with a limit...Ch. 3 - Select Show Code Pad from the View menu. Create a...Ch. 3 - What error message do you see in the Code Pad if...Ch. 3 - What error message do you see in the Code Pad if...Ch. 3 - What happens when the setValue method is called...
Ch. 3 - Prob. 11ECh. 3 - Prob. 12ECh. 3 - Which of the following expressions return...Ch. 3 - Write an expression using boolean variables a and...Ch. 3 - Write an expression using boolean variables a and...Ch. 3 - Consider the expression (a && b). Write an...Ch. 3 - Does the getDisplayValue method work correctly in...Ch. 3 - Prob. 18ECh. 3 - In Exercise 2.79 you were asked to investigate...Ch. 3 - Explain the modulo operator. You may need to...Ch. 3 - What is the result of the expression 83?Ch. 3 - Try out the expression in the Code Pad. Try other...Ch. 3 - Prob. 23ECh. 3 - Prob. 24ECh. 3 - Explain in detail how the increment method works.
Ch. 3 - Rewrite the increment method without the modulo...Ch. 3 - Open the clock-display project and create a...Ch. 3 - Prob. 28ECh. 3 - Prob. 29ECh. 3 - Prob. 30ECh. 3 - Look at the second constructor in C1ockDisplay's...Ch. 3 - Prob. 32ECh. 3 - Given a variable Printer p1; which currently holds...Ch. 3 - Open the house project from Chapter 1 and review...Ch. 3 - Prob. 35ECh. 3 - Does the Picture class contain any internal method...Ch. 3 - Remove the following two statements from the draw...Ch. 3 - Prob. 38ECh. 3 - Prob. 39ECh. 3 - Assume a class Tree has a field of type Triangle...Ch. 3 - Prob. 41ECh. 3 - Open the mail-system project, which you can find...Ch. 3 - Prob. 43ECh. 3 - Prob. 44ECh. 3 - Open the editor for the MailClient class and set a...Ch. 3 - Step one line forward in the execution of the...Ch. 3 - Prob. 47ECh. 3 - Prob. 48ECh. 3 - Prob. 49ECh. 3 - Set a breakpoint in the first line of the sendMai1...Ch. 3 - Use a combination of code reading, execution of...Ch. 3 - Use the debugger to investigate the clock-display...Ch. 3 - Prob. 53ECh. 3 - Prob. 54ECh. 3 - Prob. 55ECh. 3 - Describe the changes that would be required to the...Ch. 3 - Write the code for the timeTick method in...Ch. 3 - Discuss whether the current design of the...Ch. 3 - Challenge exercise In the current design of...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- import java.awt.*;public class TestRandomWalker {public static final int STEPS = 500;public static void main(String[] args) {RandomWalker walker = new RandomWalker(); // instantiate Walker objectDrawingPanel panel = new DrawingPanel(500, 500);Graphics g = panel.getGraphics();// advanced features -- center and zoom in the imagepanel.getGraphics().translate(250, 250);panel.getGraphics().scale(4, 4);// make the walker walk, and draw its movementint prevX = walker.getX(); // initialize Walker displayint prevY = walker.getY();for (int i = 1; i <= STEPS; i++) {g.setColor(Color.BLACK);g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display walker.move(); // move Walker 1 stepprevX = walker.getX(); // update x valueprevY = walker.getY(); // update y valueg.setColor(Color.RED); g.drawLine(prevX, prevY, walker.getX(), walker.getY()); // update Walker display int steps = walker.getSteps(); // record Walker stepsif (steps % 10 == 0) {System.out.println(steps + "…arrow_forwardPlease create a flowchart for the following program: // Import Scanner classimport java.util.Scanner; // Create a class Trianglepublic class Main{ // Method used to check given three sides form a valid triangle or not public static boolean isTriangle(double a, double b, double c) { // If sum of any two sides is greater than third side if((a+b > c) && (a+c > b) && (b+c > a)) { // Print triangle is valid System.out.println("Three sides form a valid triangle."); // Return true return true; } // If any of the above condition is false else {// Print triangle is invalidSystem.out.println("Three sides form a invalid triangle.\n"); // Return false return false; } } // Method used to compute the area of triangle public static double triArea(double a, double b, double c) { // Compute s double s = (a + b + c) / 2; // Compute the area of triangle double area = Math.sqrt(s*(s - a)*(s - b)*(s - c)); // Return the…arrow_forwardWrite a Rectangle class. Its constructor should accept length and width as a parameter. It should have methods that return its length, width, perimeter, and area. (Use Java) Show a demonstration where you create two separate rectangles.arrow_forward
- Java Problem. compile and run the code below: /** A class to test the Door class.*/public class DoorTester{ /** Tests the methods of the Door class @param args not used */ public static void main(String[] args) { Door frontDoor = new Door("Front", "open"); System.out.println("The front door is " + frontDoor.getState()); System.out.println("Expected: open"); }} Create a second Door object called “backDoor” with the name property “Back” and an initial state of “closed”. Verify that the object was properly created. Use the mutator to change the state of object backDoor to “open”. Verify that the mutator is working. Create a third Door object called “sideDoor” with the name property “Side” and an initial state of “open”. Verify that the object was properly created. Use the mutator to change the name of object sideDoor to “Front”. Verify that the mutator is working.arrow_forwardIn Java import java.util.Scanner;public class Image {int numberOfPhotos; // photos on rolldouble fStop; // light let it 1.4,2.0,2.8 ... 16.0int iso; // sensativity to light 100,200, 600int filterNumber; // 1-6String subjectMatter;String color; // black and white or colorString location;boolean isblurry;public String looksBlurry(boolean key){if ( key == true){return "Photo is Blurry";}else{return "Photo is Clear";}}public void printPhotoDetails (String s1){Scanner br= new Scanner(System.in);String subjectMatter=s1;System.out.println("Data of Nature photos:");System.out.println("Enter number of photos:");numberOfPhotos= br.nextInt();int i=1;while(true){System.out.println("Enter Filter number of photos"+i+":");filterNumber= br.nextInt();System.out.println("Enter colour of photo"+i+ ":");String color= br.next();System.out.println("Enter focal length of photo"+i+":");fStop= br.nextInt();System.out.println("Enter location of photo"+i+":");String location= br.next();System.out.println("Enter…arrow_forwardpublic class Geometry{public static void main(String[] args){//asks for user's choice Scanner in = new Scanner(System.in);displayMenu();selectOption(choice);System.out.println("Enter your choice (1-3): ");int choice1 = in.nextInt();System.out.println("Thanks for using the Geometry Calculator - Goodbye!");//Prints if input is a number that is not one of the choiceswhile(choice1 < 1 || choice1 > 3 ){System.out.println("Invalid choice. Please enter 1 - 3: ");choice1 = in.nextInt();}}/**Displays the menu*/public static void displayMenu(){System.out.println("Welcome to the Geometry Calculator Application");System.out.println("1. Calculate the Area of a Circle");System.out.println("2. Calculate the Area of a Rectangle");System.out.println("3. Calculate the Area of a Triangle");}/** This method calculates the area of the circle@return the area of the circle*/public static double circle()// calculates the area of the circle{Scanner in = new Scanner(System.in);System.out.println("What is…arrow_forward
- JAva Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is locatedat a point with integer coordinates and faces north, south, east, or west. Supply methods:public void turnLeft()public void turnRight()public void move()public Point getLocation()public String getDirection()The turnLeft and turnRight methods change the direction but not the location. The move method movesthe robot by one unit in the direction it is facing. The getDirection method returns a string “N”, “S”,“E”, “W”. For the new object, the initial location and facing should be specified. For the initial facing, 0means north, 1 means east, 2 means south, and 3 means west.A tester class, RobotTester, has been provided as follows to help you how to implement the Robot class.Therefore, implement the Robot class such that the following RobotTester class can be executed withoutany changes.import java.awt.Point;/**A class to test the Robot class.*/public class RobotTester{/**Tests the…arrow_forwardPlease answer the question in the screenshot. The language used is Java. Please provide the code to the question with an explanation. Please use the below code as a starting point. import java.util.*; public class CoursePlanner {// this method prints out: whether it is possible to take all the given courses and// one possible schedule for the given coursespublic static void plan(int numberOfCourses, int[][] prerequisites) {return;} // this is a helper method for plan; it returns a boolean to indicate if a given series of courses can be possibly scheduledpublic static boolean check(int numberOfCourses, int[][] prerequisites) {// remove these two linesif (RightSolution.check(numberOfCourses, prerequisites)) return false;else return true;}}arrow_forward50 public void setColor(String color) { } 51 52 이 ㅎ @0verride public boolean equals(Object o) { if ( o instanceof ColoredPoint ) { ColoredPoint p = (ColoredPoint)o; 53 54 55 return x == p.x && y == p.y && color p.color; 56 57 else 58 return false; 59 60 // if we override equals() we have to override hashCode() @0verride public int hashCode() { return Objects.hash(x, y, color); } 61 62 of E 65 66 /* tostring method Input: 67 68 69 None 70 Ουtρut : 71 String: (x,y,color) (No spaces) */ @0verride public String toString() { SYOUR CODE HERE> 72 73 of e 74 75 76 public static void main(String[] args) { ColoredPointp = new ColoredPoint( x: 2, y: 3, color: "red"); System.out.println("p = " + p); /* create point q using getlocation() */ Point q = p.getLocation(); /* q and p will have the same co-ordinates, but q has no color */ System.out.println("q="+q); System.out.println("p equal to q? " + p.equals(q)); ColoredPoint g2 = new ColoredPoint(q, color: "red"); System.out.println("q2="+g2);…arrow_forward
- Please help me fix this java code which is supposed to be a Pac-Man game Java program is below import java.awt.*; import javax.swing.JFrame.*; public class ManyPacMans extends JFrame { public void paint(Graphics g) { g.drawghostShape(60,30,40); setBackground(Color.BLUE); g.fillghostShape(130, 30,100, 80); g.drawghostShape(60,30,40); setBackground(Color.PINK); g.fillghostShape(130, 30,100, 80); g.drawghostShape(60,30,40); setBackground(Color.RED); g.fillghostShape(130, 30,100, 80); g.drawOvalpacman(30,130,50, 60); setForeground(Color.yellow); g.fillOval(130,130,50, 60); } public Ghost(String imgPath, int x, int y, int speed, boolean ip) { super(imgPath, new int[] {0,0}, GHOST_WIDTH, GHOST_HEIGHT, GHOST_FRAMERATE, x, y); super.addFramesForAnimation("scatter", "ghost_scatter.png", 0, 0, 22,0); super.speed = speed; startX = x; startY = y; scoreValue = 200; } public ManyPacMans() { initUI(); } private void initUI() { add(new…arrow_forwardWrite static methods* public static double cubeVolume(double h)* public static double cubeSurface(double h)* public static double sphereVolume(double h)* public static double sphereSurface(double h)* public static double cylinderVolume(double h)* public static double cylinderSurface(double h)that compute the volume and surface area of a cube, sphere, and cylinderPlace them in a class GeometryUse the given tester file to test your calculationsarrow_forwardComputer Science Questionarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education