Starting Out with Java: Early Objects (6th Edition)
6th Edition
ISBN: 9780134462011
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 6, Problem 1AW
l. 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.
Consider 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.
CLASS 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;
}
}
Chapter 6 Solutions
Starting Out with Java: Early Objects (6th Edition)
Ch. 6.1 - Prob. 6.1CPCh. 6.1 - Prob. 6.2CPCh. 6.1 - Describe the limitation of static methods.Ch. 6.3 - Prob. 6.4CPCh. 6.3 - What is a methods signature?Ch. 6.3 - Prob. 6.6CPCh. 6.3 - How many default constructors may a class have?Ch. 6.4 - Prob. 6.8CPCh. 6.4 - Prob. 6.9CPCh. 6.4 - Prob. 6.10CP
Ch. 6.5 - Recall the Rectangle class shown earlier in this...Ch. 6.9 - Consider the following statement: A car has an...Ch. 6.9 - Why is it not safe to return a reference to an...Ch. 6.9 - A class has a reference variable as an instance...Ch. 6.10 - Prob. 6.15CPCh. 6.12 - Look at the following statement, which declares an...Ch. 6.12 - Assume that the following enumerated data type has...Ch. 6.12 - Prob. 6.18CPCh. 6 - This type of method cannot access any non-static...Ch. 6 - Prob. 2MCCh. 6 - Prob. 3MCCh. 6 - Prob. 4MCCh. 6 - If you write this method for a class, Java will...Ch. 6 - Making an instance of one class a field in another...Ch. 6 - This is the name of a reference variable that is...Ch. 6 - This enum method returns the position of an enum...Ch. 6 - Assuming the following declaration exists: enum...Ch. 6 - You cannot use the fully qualified name of an enum...Ch. 6 - The Java Virtual Machine periodically performs...Ch. 6 - If a class has this method, it is called...Ch. 6 - CRC stands for a. Class, Return value, Composition...Ch. 6 - Prob. 11MCCh. 6 - True or False: A static member method may refer to...Ch. 6 - True or False: All static member variables are...Ch. 6 - Prob. 18TFCh. 6 - Prob. 19TFCh. 6 - Prob. 21TFCh. 6 - True or False: Enumerated data types are actually...Ch. 6 - True or False: enum constants have a toString...Ch. 6 - True or False: A class may not have more than one...Ch. 6 - True or False: A private class that is defined...Ch. 6 - public class MyClass { private int x; private...Ch. 6 - public class TwoValues { private int x, y; public...Ch. 6 - public class MyMath { public static int square(int...Ch. 6 - Assume the following declaration exists : enum...Ch. 6 - l. Consider the following class declaration:...Ch. 6 - A pet store sells dogs, cats, birds, and hamsters....Ch. 6 - Prob. 1SACh. 6 - Prob. 2SACh. 6 - Consider the following class declaration: public...Ch. 6 - Prob. 4SACh. 6 - How does method overloading improve the usefulness...Ch. 6 - Prob. 6SACh. 6 - Even if you do not write an equals method for a...Ch. 6 - A has a relationship can exist between classes....Ch. 6 - Prob. 9SACh. 6 - Is it advisable or not advisable to write a method...Ch. 6 - Prob. 11SACh. 6 - Look at the following declaration: enum Color {...Ch. 6 - Assuming the following enum declaration exists:...Ch. 6 - Under what circumstances does an object become a...Ch. 6 - Area Class Write a class that has three overloaded...Ch. 6 - InventoryItem Class Copy Constructor Add a copy...Ch. 6 - Carpet Calculator The Westfield Carpet Company has...Ch. 6 - LandTract Class Make a LandTract class that has...Ch. 6 - Month Class Write a class named Month. The class...Ch. 6 - Employee Class Modification In Programming...Ch. 6 - RetailItem Class Modification Modify this chapters...Ch. 6 - Sales Receipt File Modify the program you wrote in...Ch. 6 - Parking Ticket Simulator For this assignment you...Ch. 6 - Geometry Calculator Design a Geometry class with...Ch. 6 - Car Instrument Simulator For this assignment, you...Ch. 6 - First to One Game This game is meant for two or...Ch. 6 - Heads or TaiLs Game This game is meant for two or...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write a method called printDetails for a class that has a field of type String called name. The printDetai1s me...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
What are the bits in a binary system?
Digital Fundamentals (11th Edition)
Why is it necessary to introduce some methods and documentation from plan-based approaches when scaling agile m...
Software Engineering (10th Edition)
Write a program to print the value of EOF.
C Programming Language
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Look at the following pseudocode, which is the first line of a class definition. What is the name of the superc...
Starting Out with Programming Logic and Design (4th 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
- At most, a class can contain ____________ method(S). 0 1 2 any number ofarrow_forwardLook 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”arrow_forwardFibonacci A fibonacci sequence is a series of numbers in which each number is the sum of the two preceding numbers. For example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on… For this, you will implement a class that takes a positive integer (n) and returns the number in the nth position in the sequence. Examples When n is 1, the returned value will be 0. When n is 4, the returned value will be 2. When n is 9, the returned value will be 21. come up with the formula and base cases Implementation Create a class Fibonacci with a public static method getValue. Create a Main class to test and run your Fibonacci class.arrow_forward
- 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.arrow_forwardWrite the DEFINITION/IMPLEMENTATION (write the code) of the class movie declaration in Question 2. Write the code to implement (write the code for) the methods in the class movie. Be sure to include all using, includes and other directives necessary to complete the code.Code from Question 2 #pragma once#include <string> using namespace std; class MOVIE { private: string movieTitle; string movieStar; int movieRelYear; public: MOVIE(); movie(string, string, int); void print(); void set_movieTitle(int); void set_movieStar(string); void set_movieRelYear(string); }arrow_forwardJava Programming problem Create a checking account class with three attributes: account number, owner’s name, and balance. Create constructor, getters and setters. If one is to set the initial balance of an account as a negative value in a setter or a constructor, remind the user about the error and set it as 0. Create a CheckingAccountDemo class, and create a main method in which Ask for the name, account number, and initial balance for one account from the keyboard input. With these input values as arguments in a call to the constructor, create a CheckingAccount object. Print the summary of this account that includes information on the name, account number, and balance by calling the getters.arrow_forward
- IN JAVA PLEASE Child Class: Vegetable Write a child class called Vegetable. A vegetable is described by a name, the number of grams of sugar (as a whole number), the number of grams of sodium (as a whole number), and whether or not the vegetable is a starch. For the Vegetable class, write: the complete class header the instance data variables a constructor that sets the instance data variables based on parameters getters and setters; use instance data variables where appropriate a toString method that returns a text representation of a Vegetable object that includes all four characteristics of the vegetablearrow_forward2)Start by completing the constructor. The Sedan constructor takes only one argument (MPG) since the type will be “Sedan” for all Sedan objects. Write the efficient() method to return true if the MPG is greater than 30.0, false otherwise. Since the MPG are only stored in the superclass, you will need to access it using the getter method that is provided. starter Code Car.java: public class Car { private String type; private double mpg; public Car(String type, double mpg){ this.type = type; this. mpg = mpg; } public double getMPG(){ return mpg; } } Sedan.java: public class Sedan extends Car { public Sedan(double mpg){ // Complete the constructor with a call to the Superclass } public boolean efficient(){ // Enter your code here } } CarTester.java: public class CarTester { public static void main(String[] args) { Sedan clarity = new Sedan(52.7); Sedan bmw = new Sedan(22.6); System.out.println(clarity.efficient()); System.out.println(bmw.efficient()); } }arrow_forwardThe following code is in Java: public class Vehicle // Superclass { private double cost; public Vehicle(double c) { cost = c; } (Other methods . . .) // assume these are given and they’re OK. } public class Car extends Vehicle // Subclass { private int passengers; public Car(int p) { passengers = c; } (Other methods . . .) // assume these are given and they’re OK. } 1) What problems are in the code above?2) What is needed to fix the issue of the code?arrow_forward
- Question 1 ( Java Programming)1. Create a class called Parents with private variables of type String, mother and father, and also two private variables for their birthday year in type integer. (a) Create a constructor to initialize all four variables. (b) Create another constructor (overloading) to initialize variables mother and father only. (c) Create getters and setters for the variables. (d) Create a method called parentsAge which display your parents’ age based on the birthday year that you input in the test class. 2. Create a child class for Parents called Siblings (a) Create two variables called brother and sister of type String. (b) Create a constructor to initialize all variables including the variables from Parents class. All together there should be six number of arguments. (c) Create another constructor (overloading) that initialize all the variables including variables from Parents (minus the age). All together there should be four number of arguments. (d) Create a method…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_forwarda.)Write a Java statement that increments the value of count by 1. b.) Write a Java statement that outputs the value of count. C.) Write the 6 definition of constructors and the methods of the class MyClass as described in its definition.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 LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft 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
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