# Question 3: Class and Methods print ("### Question 3: Class and Methods") II IIII 1. Import the "math" library to use the pi constant. 2. Implement a "Circle" class with meaningful doc-strings for the class and methods: 2.1 Implement the constructor to create a new cirlce with only one property using the given radius. 2.2 Implement a class method to report the radius of the circle. 2.3 Implement a class method to report the perimeter of the circle. 2.4 Implement a class method to report the area of the circle. 2.5 Implement the "<" comparison operation comparing the radii of two circles. 2.6 Implement the "<=" comparison operation comparing the radii of two circles. Test: help(Circle) cirl = Circle (1.0) print("radius", cir1.getRadius ()) print ("perimeter", cir1.getPerimeter ()) print ("area", cir1.getArea (0) cir2 = Circle(2.0) print ("<", cir1 < cir2) print (">", cir1 > cir2) print("<=", cir1 <= cir2) print(">=", cir1 >= cir2) print ("!=", cir1 != cir2) print("==", cir1 == cir2)
Q: Write a program using method overloading and constructor overloading to do the following tasks. a)…
A: public class Speed { //declaring variables private double U; private double A; private double K;…
Q: Write a program using method overloading and constructor overloading to do the following tasks. a)…
A: Given:
Q: . Exercise # 2: Implement a class Portfolio. This class has two objects, checking and saving, of the…
A: Required:
Q: TOPIC: Inheritance In Python, modify the given code based on the given specifications below. Create…
A: TOPIC: Inheritance In Python, modify the given code based on the given specifications below. Create…
Q: Q3: (Practical Question) Create a C++ class and name it Vehicle. The class Vehicle has two constant…
A: Answer
Q: Class RightTriangle Represents a right triangle by the length of each of its two legs Includes the…
A: Program code: //import the required packagesimport java.util.TreeMap;//define the class…
Q: 5. Define a class Student to create Student Objects. The class defines two variables for its…
A: Student.java ============== public class Student { //create variables private String name; double…
Q: Complete the following piece of java code (MyDate class). The semicolon after each method must be…
A: Question given: A piece of object oriented programming code is given. Complete this code by…
Q: Create another C++ class and call it Car. The Car class inherits form Vehicle class and has another…
A: #include <iostream>using namespace std; // to convert int to stringstring toString(int num){…
Q: Develop the ‘Shape’ application such that: ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit…
A: Program plan:Define a class named “Shape”.Define a default constructor to print constructor invoked…
Q: (B) Add a class named Square.java • Give it private attributes double side and String color • Make a…
A: Below is the required code in java and sample output:
Q: Create a class circle class with radius as data member. Create two constructors (no argument, and…
A: Class A class is user define interface which act as blueprint for creating objects and instances…
Q: (B) Add a class named Square.java Give it private attributes double side and String color Make a…
A: checkfurther steps for the answer :
Q: . Exercise # 2: Implement a class Portfolio. This class has two objects, checking and saving, of the…
A: Here is the detailed and simplified python code for the above listed problem statement:
Q: • Exercise # 1: Define a class Point that represents a point in 2 - D plane. The point has x and y…
A: Program Approach: Declaring the class Defining the constructor sets x, y coordinates Declaring the…
Q: Q1: Create class Year (year int, month int, day int as an instance variables) Create class Time…
A: Answer: Both above question are same I have done code for one another is analogous
Q: Create the a Person class with the following: Class Variables String firstname String lastname int…
A: Actually, Java is a high level programming language. And also object oriented . It. Is a platform…
Q: 4. Define the Circle2D class that contains: > Two double data fields named x and y that specify the…
A: Program:…
Q: Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E"…
A: Please give positive ratings for my efforts. Thanks. ANSWER Part 1-9 : In Java, composition…
Q: Hint: In all your answers, implement all the methods out of the classes 1. Define a constructor with…
A: r is an array of Room objects and thus we can set the values of length and width of each room in…
Q: What is the difference between overriding a method and overloading a method? Select the correct…
A: Method overloading and method overriding are the object oriented features where we can have…
Q: 1. Define the class and its attributes. Note that Birthday is a subclass of Calendaritem [0.5 pt] 2.…
A: Given:
Q: 3. Import Class a) Import pi only from math module. b) Implement a class Circle with an attribute,…
A: code is in next step:
Q: 2. Implement the class Toy. The constructor takes as parameters the receiver's name, the price, the…
A: class Gift{ private String receiver; private double price; public Gift(r,p){…
Q: Develop the ‘Shape’ application such that: ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit…
A: Program plan:Define a class named “Shape”.Define a default constructor to print constructor invoked…
Q: Preliminaries • Write a Point class with two properties: 1, y. Write required constructor, get &…
A: Please give positive ratings for my efforts. Thanks. PROGRAM class Point { int x,y; public…
Q: (B) Add a class named Square.java Give it private attributes double side and String color • Make a…
A: Given The answer is given below. Below is the required code in java and sample output:
Q: A SuperDie Class Write a class SuperDie that models a single die with an arbitrary number of sides,…
A: Along with main method, there will be default constructor, parameterized constructor, getter and…
Q: 1. Modify your program from 04 Hands-on Activity 1 to apply encapsulation. Make bloodType and…
A: The program is written in Java. Please find the source code in step 2.
Q: Exercise 2: a) Write a class Rectangle allowing you to build a rectangle endowed with length and…
A: The answers of exercise 2 are given below. Please repost the question to get the solution of the…
Q: TOPIC: Inheritance In Python, modify the given code based on the given specifications below. Create…
A: Solution: Given, In Python, modify the given code based on the given specifications below.…
Q: Text Class The Text class inherits from Drawable and it will be used to display the player's score.…
A: It is defined as an interpreted, object-oriented, high-level programming language with dynamic…
Q: uestion 1: Write a java program for a simple calculator. The program accept two numbers from user.…
A: Actually, java is a object oriented programming language. It is a platform independent.
Q: Create a Metal class that has at least one weight property. Write proper constructor and other…
A: Java code for above scenario :- class Metal{ public int wt; public Metal(int weight){…
Q: Class Implementation a) Implement a class PlayCard with three attributes, rank, suit, and players.…
A: 1) Below is Python program to implement class PlayCard with three attributes, rank, suit, and…
Q: • Exercise # 2: Implement a class Portfolio. This class has two objects, checking and saving, of the…
A: CODE IN PYTHON: class BankAcount: def __init__(self, initialBalance = 0.0):…
Q: 1. Implement the class bill: a. Write the constructor that takes as parameters all data fields…
A: the code is an given below :
Q: Create a checking account class with three attributes: account number, owner’s name, and balance.…
A: import java.util.Scanner; public class CheckingAccountDemo { public static void main(String[] args)…
Q: 5. Design a class named Person and its two subclasses named Student and Employee and Faculty and…
A: As per bartleby guidelines for more, than one question only 1st one is to be answered. Please upload…
Q: he true statements. Select all that apply: -Static methods of a class can be called without…
A: Lets see the solution.
Q: Problem Description: Write a class Battery that models a rechargeable battery. A battery has a…
A: The program is written in java class Battery{ double capacity; double original_capacity;…
Q: 2) Implement the class Film • The description data field is composed of the name and genre of the…
A: Use split method at # to get the name and genre from description
Q: IN JAVA PLEASE Child Class: Vegetable Write a child class called Vegetable. A vegetable is described…
A: We need to write a Java class for the given scenario.
Q: 1. Implement the class Gift. Note the following: • The constructor takes as parameters the price and…
A: Class Gift has 2 instance members : receiver , price. 1 constructor : Gift(receiver, price). 1…
Q: Import Class a) Import pi only from math module. b) Implement a class Circle with an attribute,…
A: In this question we have to write a python code class program with circle and rectangle classes with…
Q: 10.11 (Geometry: the Circle2D class) Define the Circle2D class that contains: 1 Two double data…
A: The program contains the instructions to solve the problems and returns the result. The main…
Q: Indicate whether the statement is true or false. 13. The non-static methods of a class are called…
A: Defined the given statements true or false
Q: 1 Create a module named numericquestions. Inside the comdule create NumericQuestion class as a…
A: Answer: our instruction is answer the first three part from the first part and . I have attached…
Q: Please write code in JAVA Step 1: An Account class stores a current balance, and provides…
A: ANSWER:-
Please attach screenshots of code and output
screenshots are must needed
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 7 images
- Java Use eclipse for this exercise. Create a class for pets. There should be fields for name, name of owner, species (dog, cat, etc.), breed (basset hound, domestic shorthair, etc.), age (a double), and weight (a double). Create a default constructor that does nothing and a constructor that will initialize all fields using values passed in as parms. Create a method isSpecies which has one parm, a String. Return true if the species in this is the same as the parm, otherwise return false. For example, if the parm is "hamster", then the method will return true if this is a hamster, and will return false if it's not. Create a toString method that returns a String containing all fields. You can create a multi-line String by including newlines; make sure the String is nicely formatted. Do NOT create any set or get methods. Client/demo/driver code (in a separate class): Write a method to read Pets from a file. The method will have one parm which is an array of Pets. The input file is named…Create a class Animal Create a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal (String name) //constructor public void makes Sound () with the implementation printing out a generic animal sound. Next, override (add) the makes Sound() method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don't make sounds!) Note, you'll also need a constructor in each of your subclasses which calls super(name) to initialize the common 'name' member of Animal. Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. (you should observe the makeSound method called will be: cat -> from Cat class, dog-> from Dog class, bearded Dragon -> from Animal class ) EC:…1/ Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000, withdraws $500, withdraws another $400, and then prints the remaining balance. Also print the expected result 2/ Implement a class Employee. An employee has a name (a string) and a salary (a double). Provide a constructor with two arguments public Employee(String employeeName, double currentSalary) and methods public String getName() public double getSalary() public void raiseSalary(double byPercent) These methods return the name and salary, and raise the employee's salary by a certain percentage. Sample usage: Employee harry = new Employee("Hacker, Harry", 50000); harry.raiseSalary(10); // Harry gets a 10 percent raise Supply an EmployeeTester class that tests all methods. 3/Implement a class Car with the following properties. A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank. The efficiency is specified in…
- *using java* Create a class AnimalCreate a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal(String name) //constructor public void makesSound()with the implementation printing out a generic animal sound. Next, override (add) the makesSound()method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don’t make sounds!)Note, you’ll also need a constructor in each of your subclasses which calls super(name) to initialize the common ‘name’ member of Animal. --- Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. ( you should observe the implementation of the makeSound() method called will be: cat -> from Cat class, dog-> from Dog class,…Create a Main class. Create a static method in the main class isPalindrome and implement the functionality to check whether a number is a palindrome or not. Declare variables: inputNumber, reversedNumber, remainderNumber. Initialize the inputNumber and store it in the new variable originalNumber. Use a while loop and perform logic to print the reverse number of inputNumber. Compare reversed reversedNumber with originalNumber. After comparing the numbers, print "Palindrome” or "Not a Palindrome" to reflect the results. PalindromeNumberTest.java: public class Main { public static void main(String[] args) { // Paste the code for your tests here. } } PalindromeNumber.java: public class Main { public static void main(String[] args) { // Paste your code for testing a palindrome here. } }2-Create a class named 'Shape' with a method to print "This is This is shape".Then create two other classes named 'Rectangle', 'Circle' inheriting the Shapeclass, both having a method to print "This is rectangular shape" and "This iscircular shape" respectively. Create a subclass 'Square' of 'Rectangle' having amethod to print "Square is a rectangle". Now call the method of 'Shape' and'Rectangle' class by the object of 'Square' class.
- ANSWER IN JAVA: 3.14 (Date Class) Create a class called Date that includes three instance variables-a month (type int), a day (type int) and a year (type int). Provide a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes (/). Add a main method to the class that demonstrates class Date's capabilities. STANDARD OUTPUT: Enter·the·month,·day·and·year·in·the·form·XX·XX·XXXX·and·hit·enter:The·Date·object's·state·is:·11/5/1929↵ Enter·a·new·year:The·Date·object's·state·is:·11/5/1978↵ Enter·a·new·day:The·Date·object's·state·is:·11/12/1978↵ Enter·a·new·month:The·Date·object's·state·is:·6/12/1978↵Extend the ItemToPurchase class to contain a new attribute. item_description (string) - Set to "none" in default constructor Implement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps. Parameterized constructor which takes the customer name and date as parameters Attributes customer_name (string) - Initialized in default constructor to "none" current_date (string) - Initialized in default constructor to "January 1, 2016" cart_items (list) Methods add_item() Adds an item to cart_items list. Has parameter ItemToPurchase. Does not return anything. remove_item() Removes item from cart_items list. Has a string (an item's name) parameter. Does not return anything. If item name cannot…in java Create a class for Student and implement all the below listed concepts in your class. Read lecture slides for reference. Class Name: Student 1. Data fields studentID name email majorDepartmentSelect proper datatypes for these variables. 2. Constructors – create at least 2 constructors No parameter With parametersSet id and name using the constructor with parameters. 3. Methods toString method : To print the details of the Student. Setter and getter methods 4. A static variable count : To keep the count of Student objects5. Visibility Modifiers: private for data fields and public for methods 6. Write some test cases in main method
- Part 1: Setting the turtle size when it is instantiated Currently, a turtle is created and given a default size of 50. To change the size of the turtle its increaseTurtleSizeBy10 and decreaseTurtleSizeBy10 methods can be called. Add functionality so that a turtle can be created with a specified size. In the DoodleTurtle class do the following: Overload the DoodleTurtle constructor by creating a one-parameter constructor that takes the size of the turtle as an integer. Add an empty method body. Complete the method specification for the new constructor. The default constructor method specification can be used as a model. The only difference will be that the getTurtleSize() will equal the name of the size parameter instead of INITIAL_SIZE. In the method body of the one-parameter constructor do the following in this order: Call the initializeWithDefaultValues helper method. Call the setSize method passing it the size parameter. Compile the program and fix any…Define a java Name class with attributes: String firstname, middle name, lastname. Include the following methods: - A constructor with 3 parameters. Initialize the 3 member variables to the parameters being passed. Also, include the default constructor. - getter and setter methods for all attributes - override toString method Define a class called DebitCard. A debit card has a card number, Name and balance. a) Include a constructor with 3 parameters. Initialize the 3 member variables to the parameters being passed. Also, include the default constructor. b) Include getters/setters for all attributes. c) Add the following member functions: float inquireBalance() float depositCash(float amount) //increases the balance with amount boolean withdrawCash(float amount) // returns true if sufficient amount is available for withdrawal and decreases the balance by amount float interest(float rate) //calculates the interest rate incurred. Assume the parameter rate is considered as…Define a java Name class with attributes: String firstname, middle name, lastname. Include the following methods: - A constructor with 3 parameters. Initialize the 3 member variables to the parameters being passed. Also, include the default constructor. - getter and setter methods for all attributes - override toString method Define a class called DebitCard. A debit card has a card number, Name and balance. a) Include a constructor with 3 parameters. Initialize the 3 member variables to the parameters being passed. Also, include the default constructor. b) Include getters/setters for all attributes. c) Add the following member functions: float inquireBalance() float depositCash(float amount) //increases the balance with amount boolean withdrawCash(float amount) // returns true if sufficient amount is available for withdrawal and decreases the balance by amount float interest(float rate) //calculates the interest rate incurred. Assume the parameter rate is considered as…