Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 8, Problem 1AW
Consider the following class declaration:
public class Circle
{
private double radius;
public Circle(double r)
{
radius = r;
{
public double getArea()
{
return Math.PI * radius * radius;
}
public double getRadius()
{
return radius;
}
}
- a. Write a toString method for this class. The method should return a string containing the radius and area of the circle.
- b. Write an equals method for this class. The method should accept a Circle object as an argument. It should return true if the argument object contains the same data as the calling object, or false otherwise.
- c. Write a greaterThan method for this class. The method should accept a Circle object as an argument. It should return true if the argument object has an area that is greater than the area of the calling object, or false otherwise.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
using jave:
Create the a Person class with the following:
Class Variables:String firstname String lastname int birthmonth int birthday int birthyear String ssn (All variables above should be private)
Constructor The main constructor should take in all values and assign them to their respective private class variables
MethodsCreate a public getters and setters for firstname and lastname and SSN getFirstname getLastname setFirstname setLastname
Create a public getter method called getBirthdate, which will return a String composed of their birthday in month/day/year format. For example, if birthmonth=3, birthday=22, birthyear=2000, it should return the String "3/22/2000"
Create a public method called verifySSN that takes in a String parameter and returns a boolean. It will check the parameter against the person's SSN and return true or false based on whether they match.
Given the following class:
public class Student {
private long ID;
private String name;
}
Write two constructor methods for the Student class, one without parameters and the other with.
Look at the following partial class definition, and then respond to the questions that follow it:
public class Student
{
private String Name;
private String ID;
private String Email;
}
a. Write a constructor for this class. The constructor should accept an argument for each
of the fields.
b. Write a ‘sendEmail” method, that takes one argument of character type called Grade.
This method should print output to screen as below replacing the variable with actual values:
Dear ‘Name’,
You have received grade ‘Grade’.
This email is being sent to your email address at “Email”
Chapter 8 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 8.1 - Prob. 8.1CPCh. 8.1 - Prob. 8.2CPCh. 8.1 - Describe the limitation of static methods.Ch. 8.8 - Prob. 8.4CPCh. 8.9 - Look at the following statement, which declares an...Ch. 8.9 - Assume that the following enumerated data type has...Ch. 8.9 - Prob. 8.7CPCh. 8 - This type of method cannot access any non-static...Ch. 8 - Prob. 2MCCh. 8 - If you write this method for a class, Java will...
Ch. 8 - Making an instance of one class a field in another...Ch. 8 - This is the name of a reference variable that is...Ch. 8 - This enum method returns the position of an enum...Ch. 8 - Assuming the following declaration exists: enum...Ch. 8 - You cannot use the fully qualified name of an enum...Ch. 8 - The Java Virtual Machine periodically performs...Ch. 8 - If a class has this method, it is called...Ch. 8 - CRC stands for a. Class, Return value, Composition...Ch. 8 - True or False: A static member method may refer to...Ch. 8 - True or False: All static member variables are...Ch. 8 - Prob. 14TFCh. 8 - Prob. 15TFCh. 8 - Prob. 16TFCh. 8 - True or False: Enumerated data types are actually...Ch. 8 - True or False: enum constants have a toString...Ch. 8 - public class MyClass { private int x; private...Ch. 8 - Assume the following declaration exists : enum...Ch. 8 - Consider the following class declaration: public...Ch. 8 - Consider the following class declaration: public...Ch. 8 - A pet store sells dogs, cats, birds, and hamsters....Ch. 8 - Prob. 1SACh. 8 - Prob. 2SACh. 8 - Prob. 3SACh. 8 - Even if you do not write an equals method for a...Ch. 8 - A has a relationship can exist between classes....Ch. 8 - Prob. 6SACh. 8 - Is it advisable or not advisable to write a method...Ch. 8 - Prob. 8SACh. 8 - Look at the following declaration: enum Color {...Ch. 8 - Assuming the following enum declaration exists:...Ch. 8 - Under what circumstances does an object become a...Ch. 8 - Area Class Write a class that has three overloaded...Ch. 8 - BankAccount Class Copy Constructor Add a copy...Ch. 8 - Carpet Calculator The Westfield Carpet Company has...Ch. 8 - LandTract Class Make a LandTract class that has...Ch. 8 - Month Class Write a class named Month. The class...Ch. 8 - CashRegister Class Write a CashRegister class that...Ch. 8 - Sales Receipt File Modify the program you wrote in...Ch. 8 - Parking Ticket Simulator For this assignment you...Ch. 8 - Geometry Calculator Design a Geometry class with...Ch. 8 - Car Instrument Simulator For this assignment, you...Ch. 8 - First to One Game This game is meant for two or...Ch. 8 - Heads or TaiLs Game This game is meant for two or...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Why must programs written in a high-level language be translated into machine language before they can be run?
Starting Out with Java: From Control Structures through Objects (6th Edition)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Why is the study of database technology important?
Database Concepts (7th Edition)
Assume that the following enumerated data type has been declared: enum Creatures{ HOBBIT, ELF, DRAGON } What wi...
Starting Out with Java: Early Objects (6th Edition)
State whether each of the following is true or false. Instance variables of type boolean are given the value tr...
Java How To Program (Early Objects)
The ________ object is assumed to exist and it is not necessary to include it as an object when referring to it...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
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
- Modify the Date class below by adding a new method called nextDay() that increments the Date by 1 when called and returns a new Date object. This method should properly increment the Date across Month boundary (i.e from the last day of the month to the first day of the next month). //Date class declaration public class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year private static final int [] daysPerMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //constructor: confirm proper value for month and day given the year public Date (int month, int day, int year) { //check if month in range if (month <=0 II month > 12) { throw new IllegalArgumentException( “month (“ + month + “) must be 1-12”); } //check if day in range for month if…arrow_forwardModify the Date class below by adding a new method called nextDay() that increments the Date by 1 when called and returns a new Date object. This method should properly increment the Date across Month boundary (i.e from the last day of the month to the first day of the next month). //Date class declaration public class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year; // any year private static final int [] daysPerMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; //constructor: confirm proper value for month and day given the year public Date (int month, int day, int year) { //check if month in range if (month <=0 II month > 12) { throw new IllegalArgumentException( “month (“ + month + “) must be 1-12”); } //check if day in range for month if…arrow_forwardCLASS AND OBJECT WRITE! 1.) Write the main class of the given class Animal below that set the number of legs to “4” and display (get) the number of legs. class Animal { private int numberOfLegs; public void setNumberOfLegs(int numberOfLegs) { this.numberOfLegs = numberOfLegs; } public int getNumberOfLegs() { return numberOfLegs; } }arrow_forward
- At most, a class can contain ____________ method(S). 0 1 2 any number ofarrow_forwardConsider the following class: Use C++ please. Code: class Vehicle{ private: int horsepower; public: string nickname; bool fasterThanSound;; //your method here //}; //your main code here int main() {} 1.)Define a method for this class speedUp() that will increase the horsepower of the vehicle by 100. 2.)Next, in main(): Declare a Vehicle object and call the speedUp() method on the object.arrow_forwardCreate a class called Jug that represents a jug of liquid. The UML for this class is shown below: Jug private String liquidType private int gallons public Jug public Jug(String type, int gal) public void setGallons() public void getGallons() public String getLiquidType() public boolean isEmpty() Your class should have the following private state: liquidType (a string) gallons (an integer) Your class should have the following constructors: A default constructor that creates an empty jug of water. A constructor that accepts the type of liquid the jug contains, and the number of gallons the jug contains, in that order. Your class should have the following behaviors: A method called setGallons that allows you to set the number of gallons in the jug. A method called getGallons that allows you to get the number of gallons in the jug. A method called getLiquidType that allows you to get the type of liquid in the jug. A method called isEmpty that returns true if the…arrow_forward
- Write the complete equals method (including the method header) for the Appliance class. Two appliance objects are logically equivalent if they have the same description (ignoring capitalization), id (ignoring capitalization), and price. As an example, the two appliances with this data would be considered equal: "dishwasher", "ABC123", 999"DISHWASHER", "abc123", 999 Here is the appliance class: public class Appliance { private String description; private String id; private int price; // using an int for simplicity public Appliance(String description, String id, int price) { this.description = description; this.id = id; this.price = price; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getId() { return id; } public void setId(String id) { this.id = id; } public int getPrice() {…arrow_forwardIN JAVA Look at the following class definition: public class Dog {private int age = 0; // age is given in years, the default value is 0private String name = "Fido"; // default name is FidoDog(String firstName, int firstAge) {name = firstName;age = firstAge;if (age < 0) {age = 0;}}public void setName(String newName) {name = newName;}public int getAge() {return age;}public String getName() {return name;}public void haveBirthdayParty() {age = age + 1;System.out.println("Happy birthday " + name + "! You are now " + age + " years old!");}public void printInfo() {System.out.println("This dog's name is " + name + " and he's " + age + " years old!");}} Make a post containing your answers to all of the questions below: Can you create a new dog without specifying its name? Why or why not? Which of the Dog class's methods are accessors? Which ones are mutators? Can you use the methods provided to make a dog younger? (In other words, can you set age to a lower value than it already was?)…arrow_forwardModify the Car class example and add the following: A default constructor that initializes strings to “N/A” and numbers to zero. An overloaded constructor that takes in initial values to set your fields (6 parameters). accel() method: a void method that takes a double variable as a parameter and increases the speed of the car by that amount. brake() method: a void method that sets the speed to zero. To test your class, you will need to instantiate at least two different Car objects in the main method in the CarDemo class. Each of your objects should use a different constructor. For the object that uses the default constructor, you will need to invoke the mutator methods to assign values to your fields. Invoke the displayFeatures() method for both objects and display the variables. Demonstrate the use of the accessor method getColor() by accessing the color of each car and printing it to the console. Use the method accel to increase the speed of the first car by 65 mph. Use…arrow_forward
- public Account (double initialBalance){balance = initialBalance;}public Account () {balance = 0;}public void deposit (double amount){balance += amount; // Balance = balance + amount}public void withdraw (double amount){balance -= amount; // balance = balance - amount}public void close (){balance = 0;}public String toString(){return "balance: " + balance;}} Modify the Account class by adding two instance variables containing the customer's name and the account number. Both will be String objects. Modify the primary constructor for the Account class so that it takes three parameters: the balance, the customer's name, and the account number. Add instance methods named getCustomerName and getAccountNumber that return the customer name and account number.arrow_forwardEmail- date: Date- subject: String- urgent: boolean+ Email(date:Date,urgent:boolean,subject:String)+ getDate(): Date+ setDate(date: Date): void+ getSubject(): String+ setSubject(subject:String): void+ isUrgent(): boolean+ setUrgent(urgent: boolean): void+ toString(): String Write java code for all the methods shown on the class diagram. Below arethe details needed for the different methods:a. The default constructor will assign the subject and date default values.b. The overloaded constructor should initialize the instance variables withthe parameters passed to the constructor.c. The toString() method should print the information of an email, theurgent flag, date, and the subject of the emailarrow_forwardI tried to get this answered before but I couldn't get the code to work fully from what he gave me. " //Definition of class rectangle public class Rectangle { //Declare required variables private double w; private double h; //No-argument constructor public Rectangle() { //Assign "w" to "1" w = 1; //Assign "h" to "1" h = 1; } //Parameterized constructor public Rectangle(double wid, double ht) { //Assign "wid" to "w" this.w = wid; //Assign "ht" to "w" this.h = ht; } //Method definition for width public double getWidth() { //Return width return w; } //Method definition for height public double getHeight() { //Return height return h; } //Method definition for perimeter public double getPerimeter() { //Return the perimeter return 2.0*(w + h); } //Method definition for area public double getArea() { //Return the area return w*h; } }//Definition of test class public class Test { //Definition of main class public static void main(String[] args) { //Create an object for rectangle class…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY