Concept explainers
Suppose a
class Shape
{
private:
double area;
public:
void setArea(double a)
{ area = a; }
double getArea()
{ return area; }
};
class Circle : public Shape
{
private:
double radius;
public:
void setRadius(double r)
{ radius = r;
setArea(3.14 * r * r); }
double getRadius()
{ return radius; }
};
Answer the following questions concerning these classes:
A) When an object of the Circle class is created, what are its private members?
B) When an object of the Circle class is created, what are its public members?
C) What members of the Shape class are not accessible to member functions of the Circle class?
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
STARTING OUT WITH C++ REVEL >IA<
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Database Concepts (8th Edition)
C++ How to Program (10th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
- In this exercise, you have to calculate the student's total marks using the concept of Classes Problem Statement# Write a Java class called Student with ● private fields: ○ name(String type) ○ mark1 and mark2 (double type) And methods: ● getMarks(int markNumber), a method which should return mark1 if markNumber equals 1 and mark2 otherwise. ● calcTotal() method should take the two marks entered and return their sum. Also define two constructors: ● A default constructor that takes no parameters and initializes the values to zeros and null. ● A constructor that takes the three variables and sets them as the values of the appropriate fields. Input# Name of the student and the marks obtained in the first and second tests Output# Sum of both marks Sample Input# Student student = new Student("Jack", 60, 70); Sample Output# getMarks(1) => 60 getMarks(2) => 70 calcTotal() => 130.0 Part of solution class Student { // Define private fields here public Student() { // Write…arrow_forwardclass Point with instance variables as: xCoordinate(int) and yCoordinate(int). Write public instance methods (getters & setters) for each instance variable. Now, write a class Circle with private instance variables as radius and Pi (value is 3.14). Write public setter, getter for radius, Area method for calculating Area, Draw method for radius. Formula for calculating area=pi*r^2 Formula for calculating radius=Math.sqrt(xCordinate^2+yCordinate^2) Extend a Circle class from Point class such as Class Circle extends Point Write a Default constructor in Circle class that sets radius, xCoordinate&yCoordinate to some default value e.g. -1; Write a Parameterized constructor in Circle class which takes xCoordinate, yCoordinate and radius as a parameter. E.g. Circle (int xCoordinate, int yCoordinate, double radius) { this.xCoordinate= xCoordinate; this.yCoordinate= yCoordinate;…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
- Question: (use java program) (Person, Student, Employee, Faculty and Staff classes) 1) Design a class named Person which has a name, address, phone_number and email_address with the toString() method. 2) Create 2 sub-classes from Person called Student and Employee 3) Student has class status (which is constant) - Fresh-man or junior or Senior. 4) Employee has an office_location and Salary 5) Create 2 sub-classes from Employee called Faculty and Staff. 6) Faculty has office_hours and rank 7) Staff has title Overirde the toString() method in each class to display the class name and Person's name. Hint:arrow_forwardPython Programming 3. Write an Employee class that keeps data attributes for the following pieces of information:(a). Employee name(b). Employee numberNext, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information:(c). Shift number (an integer,such as1 for morning shift, 2 for evening shift)(d). Hourly payrateWrite the appropriate accessor and mutator methods for each class.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_forward
- Consider the following class: 1.Write its default constructor 2.Write a code to declare an object from this class using the default constructor public class Dog { String name; String color; void barking() { } void hungry() { } void sleeping() { } }arrow_forwardJava - Polymorphism 1.Create a class named “Animal” that has the method sound() which prints “Animals make sound.” 2.Create a class named “Cat”, “Dog”, “Pig”, “Rat” which all extends the “Animal” class. 3.Override the sound() method from Animal. These are the sound of the animals: Cat - prints "*meow meow*" Dog - prints "*barf barf*" Pig - prints "*oink oink*" Rat - prints "*squeak squeak*" 4.Call the sound() methods in the same order as stated in #3.arrow_forwardPython program for this project: Patient Charges Write a class named Patient that has attributes for the following data: First name, middle name, and last name Address, city, state, and ZIP code Phone number Name and phone number of emergency contact The Patient class’s _ _init_ _ method should accept an argument for each attribute. The Patient class should also have accessor and mutator methods for each attribute. Next, write a class named Procedure that represents a medical procedure that has been performed on a patient. The Procedure class should have attributes for the following data: Name of the procedure Date of the procedure Name of the practitioner who performed the procedure Charges for the procedure The Procedure class’s _ _init_ _ method should accept an argument for each attribute. The Procedure class should also have accessor and mutator methods for each attribute. Next, write a program that creates an instance of the Patient class, initialized with sample data. Then,…arrow_forward
- write in Java Using JOptionPane.showInputDialog Design an abstract class named BankAccount to hold the following data for a bank account:• Balance• Number of deposits this month• Number of withdrawals• Annual interest rate• Monthly service charges The class should have the following methods:Constructor: The constructor should accept arguments for the balance and annual interest rate.deposit: A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits.withdraw: A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals.calcInterest: A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the…arrow_forwardwrite in Java Using JOptionPane.showInputDialog Design an abstract class named BankAccount to hold the following data for a bank account: • Balance • Number of deposits this month • Number of withdrawals • Annual interest rate • Monthly service charges The class should have the following methods: Constructor: The constructor should accept arguments for the balance and annual interest rate. deposit: A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits. withdraw: A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals. calcInterest: A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:…arrow_forwardJava - Constructors Create a class named Book that has the following attributes: Publisher - String Year Published - Integer Price - Double Title - String Create a constructor for the class Book that has the parameters from the attributes of the class. After, create a method for the class that displays all attributes. Ask the user for inputs for the attributes and use the constructor to create the object. Lastly, print the values of the attributes. Inputs 1. Publisher 2. Year Published 3. Price 4. Book Title XYZ Publishing 2020 1000.00 How to Win? Sample Output Published: ABC Publishing Year Published: 2022 Price: 150.00 Book Title: Stooping too low Stooping too low is published by ABC Publishing on 2022. It sells at the price of Php150.00.arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,