Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 14, Problem 5AW
Explanation of Solution
Using adapter class:
- In Java API, an adapter class is another technique for creating a listener class.
- This technique is used to eliminate the need to define empty methods for the events that the user are not interested in.
- User can extend their classes from “MouseAdapter” or “MouseMotionAdapter” classes in the place of implementing “MouseListener” or “MouseMotionListener” interfaces.
- These classes implement the “MouseListener” and “MouseMotionListener” interfaces and gives empty definitions for necessary methods.
- When user extend a class from one of the above two adapter classes, it inherits the empty methods.
- In extended class, user can override the methods which the users’ needs and then empty method definition that does not contain in the listener class...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Find the errors in the following code:
private class MyMouseListener implements MouseListener{public void mouseClicked(MouseEvent e){mouseClicks += 1;}}
1. Modify the method beginsWithVowel. Use a different way to implement the method (try method indexOf() from the String class).
2. Modify the driver class to iteratively ask the user to enter a sentence, and then translate the sentence, until the user decides to quit the program.
import java.util.Scanner;public class Translator {
//instance variables
//constructors
//methods
public static String translate(String sentence)// My name is Patrick Casseus { String result = ""; sentence = sentence.toLowerCase(); Scanner scan = new Scanner(sentence);
while(scan.hasNext()) { result = result += translateWord(scan.next()) + " "; }
return result; }
private static String translateWord(String word) { String result = "";
if(startWithVowel(word)) result = word + "yay"; else if(startWithBlend(word)) // chair -> air + ch + ay result = word.substring(2) +…
solve:
Chapter 14 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Ch. 14.1 - Prob. 14.1CPCh. 14.1 - Prob. 14.2CPCh. 14.2 - Prob. 14.3CPCh. 14.2 - Prob. 14.4CPCh. 14.2 - Prob. 14.5CPCh. 14.2 - Prob. 14.6CPCh. 14.2 - Prob. 14.7CPCh. 14.2 - Prob. 14.8CPCh. 14.2 - Prob. 14.9CPCh. 14.2 - Prob. 14.10CP
Ch. 14.2 - Prob. 14.11CPCh. 14.3 - Prob. 14.12CPCh. 14.3 - Prob. 14.13CPCh. 14.3 - Prob. 14.14CPCh. 14.3 - Prob. 14.15CPCh. 14.4 - Prob. 14.16CPCh. 14.4 - Prob. 14.17CPCh. 14.5 - Prob. 14.18CPCh. 14.5 - Prob. 14.19CPCh. 14.5 - Prob. 14.20CPCh. 14.5 - Prob. 14.21CPCh. 14.5 - Prob. 14.22CPCh. 14.5 - Prob. 14.23CPCh. 14.5 - Prob. 14.24CPCh. 14.5 - What Graphics class methods do you use to perform...Ch. 14.6 - Prob. 14.26CPCh. 14.6 - Prob. 14.27CPCh. 14.6 - Prob. 14.28CPCh. 14.6 - Prob. 14.29CPCh. 14.6 - Prob. 14.30CPCh. 14.7 - Prob. 14.31CPCh. 14.7 - Prob. 14.32CPCh. 14.7 - Prob. 14.33CPCh. 14.7 - Prob. 14.34CPCh. 14.8 - Prob. 14.35CPCh. 14.8 - Prob. 14.36CPCh. 14.8 - Prob. 14.37CPCh. 14.8 - Prob. 14.38CPCh. 14 - Prob. 1MCCh. 14 - Prob. 2MCCh. 14 - Prob. 3MCCh. 14 - Prob. 4MCCh. 14 - When using Swing to write an applet, you extend...Ch. 14 - Prob. 6MCCh. 14 - Prob. 7MCCh. 14 - Prob. 8MCCh. 14 - Prob. 9MCCh. 14 - Prob. 10MCCh. 14 - Prob. 11MCCh. 14 - Prob. 12MCCh. 14 - Prob. 13MCCh. 14 - Prob. 14MCCh. 14 - Prob. 15MCCh. 14 - Prob. 16MCCh. 14 - Prob. 17MCCh. 14 - Prob. 18MCCh. 14 - Prob. 19MCCh. 14 - Prob. 20MCCh. 14 - Prob. 21MCCh. 14 - Prob. 22MCCh. 14 - Prob. 23TFCh. 14 - Prob. 24TFCh. 14 - Prob. 25TFCh. 14 - Prob. 26TFCh. 14 - Prob. 27TFCh. 14 - Prob. 28TFCh. 14 - Prob. 29TFCh. 14 - Prob. 30TFCh. 14 - Prob. 31TFCh. 14 - Prob. 32TFCh. 14 - Prob. 33TFCh. 14 - Prob. 34TFCh. 14 - Prob. 35TFCh. 14 - Prob. 1FTECh. 14 - Prob. 2FTECh. 14 - Prob. 3FTECh. 14 - Prob. 4FTECh. 14 - Prob. 5FTECh. 14 - Prob. 6FTECh. 14 - Prob. 1AWCh. 14 - Prob. 2AWCh. 14 - Prob. 3AWCh. 14 - Prob. 4AWCh. 14 - Prob. 5AWCh. 14 - Prob. 6AWCh. 14 - Prob. 1SACh. 14 - Prob. 2SACh. 14 - Prob. 3SACh. 14 - Prob. 4SACh. 14 - Prob. 5SACh. 14 - Prob. 6SACh. 14 - Prob. 7SACh. 14 - Prob. 8SACh. 14 - Prob. 9SACh. 14 - Prob. 1PCCh. 14 - House Applet Write an applet that draws the house...Ch. 14 - Prob. 3PCCh. 14 - Thermometer Applet Write an applet that displays a...Ch. 14 - Prob. 5PCCh. 14 - Prob. 6PCCh. 14 - Prob. 7PCCh. 14 - Prob. 8PCCh. 14 - Prob. 9PC
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
- toString() and equals() Methods This lab will demonstrate how the toString() and equals() methods work when they are not overridden. Type up the code and submit the BOTH results. CODE public class ObjectToString( public static void main(String[] args) { ClassOne co new ClassOne(); ClassTwo ct = new ClassTwo(); } } public class Classone { System.out.println(co); System.out.println(ct); System.out.println(co.equals(ct)); public void printfle() { System.out.println("I am from ClassOne"); } public class ClassTwo ( public void printMe() { } System.out.println("I am from ClassTwo"); Run the program and notice the output.arrow_forwardclass Param3 { public int x; private void increase(int p) { x = x*p; } public void calculateX(int y) { increase(y); } public int getX() { return x; } } // in another class Param3 q3 = new Param3(); q3.x = 5; q3.calculateX(7); System.out.println(q3.getX()); what would be the answer for the last two lines ? also above were x = x*p do both x in here are the fields? wouldn't that be cnofusing?arrow_forwardpublic class DebugBox { privateint width; privateint length; privateint height; publicDebugBox() { length = 1; width = 1; height = 1; } publicDebugBox(intwidth,intlength,intheight) { width = width; length = length; height = height; } publicvoidshowData() { System.out.println("Width: " + width + "Length: " + length + "Height: "+ height); } publicdoublegetVolume() { double vol = length * width * height; return vol; } } // This class uses a DebugBox class to instantiate two Box objects public class DebugFour3 { publicstaticvoidmain(Stringargs[]) { int width =12, length = 10, height = 8; DebugBox box1 =newDebugBox(); DebugBox box2 =newDebugBox(width, length, height); System.out.println("The dimensions of the first box are"); box1.showData(); System.out.print("The volume of the first box is "); showVolume(box1); System.out.println("The dimensions of the second box are"); box2.showData(); System.out.print("The volume of the second box is "); showVolume(box2); }…arrow_forward
- //Todo write test cases for SimpleCalculator Class // No need to implement the actual Calculator class just write Test cases as per TDD. // you need to just write test cases no mocking // test should cover all methods from calculator and all scenarios, so a minimum of 5 test // 1 for add, 1 for subtract, 1 for multiply, 2 for divide (1 for normal division, 1 for division by 0) // make sure all these test cases fail public class CalculatorTest { //Declare variable here private Calculator calculator; //Add before each here //write test cases here }arrow_forwardWhat is included in the method private void buildLetterTable() { implemented in the class Anagramsarrow_forwardComplete the convert() method that casts the parameter from a double to an integer and returns the res Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 512334.3517088.qx3zqy7 LAB ACTIVITY 1 public class LabProgram { INM + ∞ 2 25.20.1: LAB: Write convert() method to cast double to int 3 public static int convert (double d) { /* Type your code here */ 4 5 6 7 } 8 public static void main(String[] args) { 9 System.out.println (convert (19.9)); 10 11 12} } System.out.println(convert(3.1)); LabProgram.javaarrow_forward
- Implement the following classes: Polygon numSide: int /* constructor */ /* accessor-mutator */ + area (): double + perimeter (): double Triangle sideA: double sideB: double sidec: double /* constructor */ /* accessor-mutator */ + area () : double + perimeter (): double Create an object for Triangle class and invoke area and perimeter method. Input Format Take triangle sides (sideA,sideB,sideC) as input from user. Constraints For Triangle, sideB+sideC > sideAarrow_forwardDO NOT COPY FROM OTHER WEBSITES Upvote guarenteed for a correct and detailed answer. Thank you!!!arrow_forwardCan you write a java program according to the conditions ?arrow_forward
- please answer the blanked questions. see pictures attachedarrow_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_forwardimport components.naturalnumber.NaturalNumber;import components.naturalnumber.NaturalNumber2;import components.simplewriter.SimpleWriter;import components.simplewriter.SimpleWriter1L; /*** Program with implementation of {@code NaturalNumber} secondary operation* {@code root} implemented as static method.** @author Mati Desissa**/public final class NaturalNumberRoot { /*** Private constructor so this utility class cannot be instantiated.*/private NaturalNumberRoot() {} /*** Updates {@code n} to the {@code r}-th root of its incoming value.** @param n* the number whose root to compute* @param r* root* @updates n* @requires r >= 2* @ensures n ^ (r) <= #n < (n + 1) ^ (r)*/public static void root(NaturalNumber n, int r) {assert n != null : "Violation of: n is not null";assert r >= 2 : "Violation of: r >= 2"; double lowEnough = 0;double tooHigh = n.toInt();double power = 1.0 / r;double value = Math.pow(tooHigh, power);double guess = (1.0) * tooHigh / 2; while ((int) guess !=…arrow_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
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY