Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 8, Problem 4E
Suppose we want to implement a drawing
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Suppose we want to implement a drawing program that creates various shapesusing keyboard characters. Implement an abstract base class DrawableShapethat knows the center (two integer values) and the color (a string) of theobject. Give appropriate accessor methods for the attributes. You should alsohave a mutator method that moves the object by a given amount.
Define a class in java representing physical elements (like hydrogen, helium, lithium,etc.). Elements have a name, a symbol, an integer atomic number, and an atomicweight (which may be fractional). Your class should have a constructor that setsall the properties, and a toString method that prints each element as a nicelyformatted String. Write accessors and mutators for each field if you think it isappropriate to do so (ask yourself if the field should be changeable). Update yourmain method to create and print 10 unique elements.
Need help on java homework assignment, It says
Create a class Vehicle. A Vehicle has a single instance variable of type String named "vehicleType" that describes the vehicle. It has an abstract method getTires that takes no parameters and returns an ArrayList<Tire> object that describes each Tire of the vehicle. A Tire class has been provided. Vehicle has a single constructor that takes the vehicle type as a parameter.Create a class Bicycle that extends Vehicle that has two Tires, both of type "skinny". Bicycle should have a single default constructor.Create a class Dragster that extends Vehicle and has four Tires, two of type "slick" and two of type "medium". Dragster should have a single default constructor.Write a tester program to test Bicycle and Dragster objects. Use declarations such as Vehicle b = new Bicycle();in your tester.
Here is the code provided :
public class Tire {
private String size;
public Tire(String siz) { size = siz; }
public String…
Chapter 8 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 8.1 - Prob. 1STQCh. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Suppose the class SportsCar is a derived class of...Ch. 8.1 - Can a derived class directly access by name a...Ch. 8.1 - Can a derived class directly invoke a private...Ch. 8.1 - Prob. 6STQCh. 8.1 - Suppose s is an object of the class Student. Base...Ch. 8.2 - Give a complete definition of a class called...Ch. 8.2 - Add a constructor to the class Student that sets...Ch. 8.2 - Rewrite the definition of the method writeoutput...
Ch. 8.2 - Rewrite the definition of the method reset for the...Ch. 8.2 - Can an object be referenced by variables of...Ch. 8.2 - What is the type or types of the variable(s) that...Ch. 8.2 - Prob. 14STQCh. 8.2 - Prob. 15STQCh. 8.2 - Consider the code below, which was discussed in...Ch. 8.2 - Prob. 17STQCh. 8.3 - Prob. 18STQCh. 8.3 - Prob. 19STQCh. 8.3 - Is overloading a method name an example of...Ch. 8.3 - In the following code, will the two invocations of...Ch. 8.3 - In the following code, which definition of...Ch. 8.4 - Prob. 23STQCh. 8.4 - Prob. 24STQCh. 8.4 - Prob. 25STQCh. 8.4 - Prob. 26STQCh. 8.4 - Prob. 27STQCh. 8.4 - Prob. 28STQCh. 8.4 - Are the two definitions of the constructors given...Ch. 8.4 - The private method skipSpaces appears in the...Ch. 8.4 - Describe the implementation of the method drawHere...Ch. 8.4 - Is the following valid if ShapeBaSe is defined as...Ch. 8.4 - Prob. 33STQCh. 8.5 - Prob. 34STQCh. 8.5 - What is an advantage of having the main...Ch. 8.5 - What Java construct allows us to define and...Ch. 8 - Consider a program that will keep track of the...Ch. 8 - Implement your base class for the hierarchy from...Ch. 8 - Draw a hierarchy for the components you might find...Ch. 8 - Suppose we want to implement a drawing program...Ch. 8 - Create a class Square derived from DrawableShape,...Ch. 8 - Create a class SchoolKid that is the base class...Ch. 8 - Derive a class ExaggeratingKid from SchoolKid, as...Ch. 8 - Create an abstract class PayCalculator that has an...Ch. 8 - Derive a class RegularPay from PayCalculator, as...Ch. 8 - Create an abstract class DiscountPolicy. It should...Ch. 8 - Derive a class BulkDiscount from DiscountPolicy,...Ch. 8 - Derive a class BuyNItemsGetOneFree from...Ch. 8 - Prob. 13ECh. 8 - Prob. 14ECh. 8 - Create an interface MessageEncoder that has a...Ch. 8 - Create a class SubstitutionCipher that implements...Ch. 8 - Create a class ShuffleCipher that implements the...Ch. 8 - Define a class named Employee whose objects are...Ch. 8 - Define a class named Doctor whose objects are...Ch. 8 - Create a base class called Vehicle that has the...Ch. 8 - Create a new class called Dog that is derived from...Ch. 8 - Define a class called Diamond that is derived from...Ch. 8 - Prob. 2PPCh. 8 - Prob. 3PPCh. 8 - Prob. 4PPCh. 8 - Create an interface MessageDecoder that has a...Ch. 8 - For this Programming Project, start with...Ch. 8 - Modify the Student class in Listing 8.2 so that it...Ch. 8 - Create a JavaFX application that uses a TextField...Ch. 8 - Prob. 10PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not in...
Starting Out with Python (4th Edition)
Modify the logic circuit for the intrusion alarm in Figure 3-25 so that two additional rooms, each with two win...
Digital Fundamentals (11th Edition)
(Adapted from Barwise and Etchemendy (1993).) Given the following, can you prove that the unicorn is mythical? ...
Artificial Intelligence: A Modern Approach
Describe the purpose of the access key attribute and how it supports accessibility.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Budget Analysis Write a program that asks the user to enter the amount that he or she has budgeted for a month....
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
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
- Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle with abstract methods getColor () and getBrand (). Now, create a concrete class Taxi with additional method setDriver (String name) that inherits both Wheel and Vehicle. (Note: Concrete classes don’t have any abstract method)arrow_forwardWhen you add a contact to your phone, it automatically sorts those names alphabetically. In this exercise, we are going to create a phonebook that automatically sorts everytime a new number is added to the phonebook. A PhoneNumber class has been created already that has the instance variables name and number. Your job is to create the PhoneBook class that will store an ArrayList of PhoneNumbers. The PhoneBook class does not have a constructor - it only contains an ArrayList that can store the individual phone numbers that are added to it. There should be three methods in the PhoneBook class: addNumber- This method takes a PhoneNumber and adds it to the directory. Once the number has been added, the sort method is called on the directory to sort that new address into the phone book. sort- This method sorts the directory in alphabetical order A-Z.a. Remember that in order to compare Strings, we can use the compareTo() method. This returns an integer that indicates whether a String’s…arrow_forwardThis way, any class that implements the Visible interface can define its own behavior for making an object visible or invisible based on its specific requirements.Create the Priority Java interface, which has the methods setPriority and getPriority. A method for determining numerical priority among a group of objects should be defined by the interface. Create and implement a class named Task that represents a task that implements the Priority interface, such as one that is on a to-do list. To test some Task objects, construct a driver class.arrow_forward
- In java language Write a Rectangle class. A Rectangle has properties of width and length. You construct a Rectangle object by providing the width and length in that order. If no width and length are provided to the constructor, construct a Rectangle with width 0.0 and length 0.0. We want to be able to get and set both the width and the length independently. We also want to be able to ask for the area of the rectangle and the perimeter of the rectangle. What will the object need to remember? width and length - those are the instance variables. Rectangle class has these constructors : public Rectangle() - Constructs a new rectangle with width and length of 0.0. public Rectangle(double width, double length) - Constructs a new rectangle with the given width and length. Remember that the job of the constructor is to initialize the instance variables. It has these methods. public double getWidth() - Gets the width of this Rectangle public double getLength() - Gets the length of this…arrow_forwardIn java language Write a Rectangle class. A Rectangle has properties of width and length. You construct a Rectangle object by providing the width and length in that order. If no width and length are provided to the constructor, construct a Rectangle with width 0.0 and length 0.0. We want to be able to get and set both the width and the length independently. We also want to be able to ask for the area of the rectangle and the perimeter of the rectangle. What will the object need to remember? width and length - those are the instance variables. Rectangle class has these constructors : public Rectangle() - Constructs a new rectangle with width and length of 0.0. public Rectangle(double width, double length) - Constructs a new rectangle with the given width and length. Remember that the job of the constructor is to initialize the instance variables. It has these methods. public double getWidth() - Gets the width of this Rectangle public double getLength() - Gets the length of this…arrow_forwardCreate a Java class called Student with attributes name, age, and grade. Implement a parameterized constructor to initialize these attributes. Then, create an array of Student objects, populate it, and print the details of all students.arrow_forward
- You are to write an Ant class to simulate Langton's Ant. In this simulation, a virtual "ant" moves about a two-dimensional square matrix, whose spaces can be designated white or black, according to the rules below: If the ant is on a white space, it will turn right 90 degrees relative to the directions it is facing, move forward one step, and change the space it left to black. If the ant is on a black space, it will turn left 90 degrees relative to the directions it is facing, move forward one step, and change the space it left to white. When the ant hits the edge of the board and is going to go out of the bounds, wrap the board around so the ant will appear on the other side. The matrix is initially composed of all white spaces. The user will specify the size of the square matrix. The user will also specify the number of steps that the ant will move and the starting location and direction of the ant. After the simulation, the final board with the ant position will be displayed to…arrow_forwardWrite a class that represents a player in a game. The player should have a name, password,experience points, an inventory array of four strings, and a location x,y. Your class shouldhave mutator and accessor methods for all variables. For example: setName(), getName(). Itshould have a suitable display method. Mutators and accessors should be public but allvariables should be private. To implement get inventory, use string * getInv(); Use the scoperesolution operator to implement larger methods such as display(). Use in class methods forshorter methods such as setName(), getName(). (in C++)Example:void setName(string name){this->name = name;}string *getInv();...string* player::getInv(){return inventory;}Note that in the above method setName “this->” is required for disambiguation. If writtenvoid setName(string n){name = n;}“this->” is not required.Write a test program that creates three players and displays them.Example Output:This program generates three player objects and…arrow_forwardThis is for pygame Ball Class: The Ball class inherits from Drawable and it will draw a circle at its current location. You must implement at the very least the required methods of the base class (draw and get_rect), as well as a constructor. You may need to implement other methods as part of the public interface. This is the Drawable Classarrow_forward
- Design an interface named Colorable with a voidmethod named howToColor(). Every class of a colorable object must implementthe Colorable interface. Design a class named Square that extendsGeometricObject and implements Colorable. Implement howToColor todisplay the message Color all four sides. The Square class contains adata field side with getter and setter methods, and a constructor for constructinga Square with a specified side. The Square class has a private double datafield named side with its getter and setter methods. It has a no-arg constructorto create a Square with side 0, and another constructor that creates a Squarewith the specified side.Draw a UML diagram that involves Colorable, Square, and GeometricObject.Write a test program that creates an array of five GeometricObjects. For eachobject in the array, display its area and invoke its howToColor method if it iscolorable.arrow_forwardWe have to calculate the area of a rectangle, a square and a circle.Create an abstract class 'Shape' with 2 dimension fields and an abstractmethod namely 'area'. Now, write 3 classes ‘Rectangle', 'Circle' and‘Triangle’ derived from the ‘Shape’ class. Implement the area() methodas necessary in each class.Now create another class 'Geometry' containing the main method andcreate objects of 'Rectangle', 'Square' and 'Circle' and printing theirarea.arrow_forwardWrite a complete program for the description given below. Consider a Billing class that implements an interface Payable having a method getTotalPayment Amount(). Besides this, you have a Doctor class with private instance variables (docID, docName, and docFee) and a public getDoc() method, Patient class with private instance variables (pName, pID. pDisease), Medicine class with private instance variables (medID, medName, medQty, medPrice), and Medical Test class with private instance variables (testID, testName, testPrice). Each of these classes has the toString() method to display the information of its object. The Billing class is having "Has A" relationship with the other four classes (Doctor, Patient, Medicine, and MedicalTest) mentioned above. The getPayment Amount() method of Billing class returns the total billing amount that includes doc fee, medicine cost, and medical test fee that a patient has to pay. After implementing these classes, you are required to do the following in…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
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License