The Java feature in Q1 which create a new version of predefined method getPerimeter() is called Polymorphism Override Overload Inheritance
Q: 4. Create an interface Wheel with methods setWheels (int c) and getWheels () and a class Vehicle…
A: Solution: Given,
Q: 2. Write an interface for Tossable. We will say that every Tossable item has a way to toss it and we…
A: Bakable.java package leetcode; public interface Bakable { public void bake(); } 2) Potato.java…
Q: A. Writing an Interface In this problem you will first write an interface and then modify classes to…
A: Let us consider a series of Java program that can modify classes to implement the interface and…
Q: Questions 1. Printing click coordinates. Build a custom subclass of JComponent which listens for…
A: According to the Bartelby guideline we are suppose to answer only one question at a time. Kindly…
Q: Implement the concept of polymorphism using interfaces in Java. • Create an interface class named…
A: Algorithm: Start Create an interface named Shape with draw() as its method Create a class named…
Q: Design a class Circle with the following Private double data for radius One no arg constructor One…
A: //note: since the programming language is mentioned we are providing answer in cpp #include…
Q: Exercise: Exercises Write a class named Octagon that extends GeometricObject and implements the…
A: The program is written in java
Q: write a class called rectangle that implements the Comparable The class should contain three fields:…
A: import java.util.*;//1. definition for Class Rectanglepublic class Rectangle implements…
Q: Define a Rectangle class that also inherits from Quadrilateral, with the following methods:…
A: Step-1: Start Step-2: Create a class Quadrilateral Step-2.1: Create constructor for variable length…
Q: We have an interface called discount strategy, that calculates discounts for a simple parking…
A: Given that We have an interface called discount strategy, that calculates discounts for a simple…
Q: Write the Java code corresponding to the following UML diagram. The class School implements the…
A: Solution: Programming language used: Java Program in Java: (Note: all solution steps are…
Q: Implement a class called BankAccount that is used to keep track of a bank account. This class will…
A: In the solution of given problem, we define the class BankAccount, with two private members id (int)…
Q: In Q3, the ColoredCircle class has two constructors with the same name but different parameters.…
A: the ColoredCircle class has two constructors with the same name but different parameters. This is…
Q: In this problem you will first write an interface and then modify classes to implement the…
A: We write the interface as shown below in GeometricSolid.java file: public interface GeometricSolid {…
Q: write an interface called polygon. this interface should have 1 method called calculate, area which…
A: interface Polygon{ //Declaring interface Polygon public void calculateArea(int length,int…
Q: s that will extend the given Animal class and optionally implement a leg count interface. (Image…
A: Given : Animal.java abstract class Animal { String FUR="fur"; String FEATHER = "feather"; String…
Q: Create a class namely Circle and do the following: (i) Circle will have the following member…
A: The program is written in java
Q: Your task is to create a Circle constructor that creates a circle with a radius provided by an…
A: Algorithm - Design a method with one argument as a string. Now use the below logic to solve the…
Q: Write a PaypalAccount class to include both balance and accountID as the instance variables. Make…
A: Java is a programming language was originally developed by James Gosling at Sun Microsystems.
Q: ate a class Rectangle with parameters length, breadth, and color. Use appropriate data types and…
A: public class TestRectangle { public static void main(String[] args) { Rectangle r1=new…
Q: Q#Assuming that we wanted to create a package that contained Polygon, Triangle, IsoscelesTriangle,…
A: the class which belongs to them is shape class hence option 1 is correct None of these should be an…
Q: Your task is to implement the following TouchNGo class. It is a subclass of DigitalWallet. The…
A: In this question we have to write a JAVA Program in which we have to write a class for TouchNGo…
Q: Q1: Write the Java code corresponding to the following UML diagram. The class School implements the…
A: Solution: Given,
Q: Assume the existence of a Widget class that implements the Comparable interface and thus has a…
A: Using binary search for the effective implementation of the getWidgetMatch(given in the question).…
Q: Implement the following classes: Polygon numSide: int /* constructor */ /* accessor-mutator */ +…
A: Note: Programming language is missing in the question. So we will answer this program in Java. If…
Q: Write a Circle class that has the following field: radius: a double The class should have the…
A: import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner…
Q: Create a generic class with a type parameter that simulates drawing an item at random out of a box.…
A: USING JAVA 5 :-
Q: 3. The interface Range is defined below: public interface Range { void setLimits(int x, int y);…
A: According to the information given:- We hvae to follow the instruction and create the interface…
Q: Create a class for the following object. Deck - contaíns 52 cards initially. Each card is…
A: Here, I have to write a java program to the above question.
Q: Questions 1. Printing click coordinates. Build a custom subclass of JComponent which listens for…
A: According to the Bartelby guideline we are suppose to answer only one question at a time. Kindly…
Q: Write a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable…
A: Actually, java is object oriented programming language. It is a platform independent.
Q: The Point2D should store an x and y coordinate pair, and will be used to build a new class via class…
A: ANSWER: Point2D: In this program we make a Point2D object named point2d_1 by utilizing its x, y…
Q: (The HyPoint class) Design a class named MyPoint to represent a point with x- and y-coordinates. The…
A: Answer
Q: Write a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable…
A: Comparable and Clonable are interfaces. This means that by saying a class supports an interface it…
Q: Q1: Write the Java code corresponding to the following UML diagram. The class School implements the…
A: Algorithm: Start Implement an interface Building with methods computeArea() and toString() Create a…
Q: java please dont take other website'answer. rthis is actually practice question ANIMALCLASS…
A: import java.util.*;import java.lang.*;import java.io.*; class Main{ public static void main(String…
Q: Design an interface named Colorable with a voidmethod named howToColor(). Every class of a colorable…
A: File name: Geo.java //class Definition public class Geo { // Main method public static…
Q: Write an interface and then modify classes to implement the interface. Write an interface,…
A: We need to make 5 java files in total in the same folder as shown: I have created a folder solid…
Q: Define a Polygon interface that has methods area() and perimeter(). Then implement classes for…
A: I attached the working code below, Please go through that code.
Q: Implement the above system using inheritance in the best possible way. Keep every object size as…
A: The given system of classes for inheritance are implemented as follows: Class Region acts is…
Q: Given the Solid class, extend it with: Pyramid Cylinder RectangularPrism Sphere Make sure to…
A: Actually, java is a object oriented programming language. It is a platform independent.
Q: Define an interface as follows: Interface Bicycle { // wheel revolutions per minute void…
A: class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int…
Q: Implement a class Triangle. A Triangle is defined by the x- and y- coordinates of its three corner…
A: Assume a triangle with three points (x1,y1), (x2y2) and (x3, y3) as shown below There are three…
Q: The interface Range is defined below: public interface Range { void setLimits(int x, int y); int…
A: Here I have created a class named RandomInteger that implements the interface Range. In this class,…
Q: In the following code: public interface Shape extends Comparablel double getArea0: We have: Select…
A: Given, public interface Shape extends Comparable<Circle>{ double getArea(); } In Java when an…
Q: An interface named SidedObject has been added that contains a method called displaySides(). Modify…
A: public interface SidedObject{ public void displaySides();}
Q: Create a class Fraction with two integer final fields: numeratorand denominator. Its constructor…
A: Introduction of the Program: The Java program makes a Fraction class and this class has two member…
Q: Create an interface called Visible that includes two methods: makeVisible and makeInvisible. Both…
A: Answer:
Q: * This class describes a tweet. A tweet has a message in it, a unique ID, * a count of the number of…
A: EXPLANATION: - The Tweet class comprises instance variables of the following instance variables: -…
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
1: create a class Pentagon, which implements the RegularPolygon interface. It should have a double field called length, as well as a constructor that initializes this length field to a given value.
2:
In the main() method of Pentagon class, add the following code:
RegularPolygon sq = new Square(10);
RegularPolygon penta = new Pentagon(20);
Write code to get the perimeter for sq and penta.
3:
In the main() method defined in Q2, add this line of code:
sq.getArea();
Will this code pass through compiler? What is the reason?
-
The Java feature in Q1 which create a new version of predefined method getPerimeter() is called
Polymorphism
Override
Overload
Inheritance
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- In this problem you will first write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double. You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. You can use Google search to find the formula for the volume. Make sure that you use Math.PI in your calculations. Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids. Provide Javadoc. Cylinder.java /*** Models a Cylinder*/public class Cylinder {private double radius;private double height; /*** Constructor for objects of class Cylinder* @param radius the radius of the Cylinder* @param height the height of this Cylinder*/public Cylinder(double radius, double height){this.radius = radius;this.height = height;}/*** Gets the radius of this…a. Write a FractionDemo program that instantiates several Fraction objects and demonstrates that their methods work correctly. Create a Fraction class with fields that hold a whole number, a numerator, and a denominator. In addition: Create properties for each field. The set access or for the denominator should not allow a 0 value; the value defaults to 1. Add three constructors. One takes three parameters for a whole number, numerator, and denominator. Another accepts two parameters for the numerator and denominator; when this constructor is used, the whole number value is 0. The last constructor is parameterless; it sets the whole number and numerator to 0 and the denominator to 1. (After construction, Fractions do not have to be reduced to proper form. For example, even though 3/9 could be reduced to 1/3, your constructors do not have to perform this task.) Add a Reduce() method that reduces a Fraction if it is in improper form. For example, 2/4 should be reduced to 1/2. Add an operator+() method that adds two Fractions. To add two fractions, first eliminate any whole number part of the value. For example, 2 1/4 becomes 9/4 and 1 3/5 becomes 8/5. Find a common denominator and convert the fractions to it. For example, when adding 9/4 and 8/5, you can convert them to 45/20 and 32/20. Then you can add the numerators, giving 77/20. Finally, call the Reduce() method to reduce the result, restoring any whole number value so the fractional part of the number is less than 1. For example, 77/20 becomes 3 17/20. Include a function that returns a string that contains a Fraction in the usual display format—the whole number, a space, the numerator, a slash (D, and a denominator. When the whole number is 0, just the Fraction part of the value should be displayed (for example, 1/2 instead of 0 1/2). If the numerator is 0, just the whole number should be displayed (for example, 2 instead of 2 0/3). b. Add an operator*() method to the Fraction class created in Exercise 11a so that it correctly multiplies two Fractions. The result should be in proper, reduced format. Demonstrate that the method works correctly in a program named FractionDemo2. c. Write a program named FractionDem03 that includes an array of four Fractions. Prompt the user for values for each. Display every possible combination of addition results and every possible combination of multiplication results for each Fraction pair (that is, each type will have 16 results).This is for pygame. Block class The Block class inherits from Drawable and it will draw a square with a black outline 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. Put all this code in a file name Block.py This is the Drawable class.
- This 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 ClassCreate a Visible interface with two methods: makeVisible and makeInvisible. Both methods should accept no parameters and return a boolean value. Explain how a class may implement this interface.Write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double. You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. Make sure that you use Math.PI in your calculations. Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids. Cylinder.java /*** Models a Cylinder*/public class Cylinder {private double radius;private double height; /*** Constructor for objects of class Cylinder* @param radius the radius of the Cylinder* @param height the height of this Cylinder*/public Cylinder(double radius, double height){this.radius = radius;this.height = height;}/*** Gets the radius of this Cylinder* @return the radius of the Cylinder*/public double getRadius(){return radius;}/*** Sets the radius of…
- Complete the Course class by implementing the findStudentHighestGpa() method, which returns the Student object with the highest GPA in the course. Assume that no two students have the same highest GPA. Given classes: Class Course represents a course, which contains an ArrayList of Student objects as a course roster. (Type your code in here.) Class Student represents a classroom student, which has three private fields: first name, last name, and GPA. (Hint: GetGPA() returns a student's GPA.) Ex: If the following students and their GPA values are added to a course: Henry Nguyen with 3.5 GPABrenda Stern with 2.0 GPALynda Robison with 3.2 GPASonya King with 3.9 GPA then the findHighestStudent() method returns a student and the program output is: Top student: Sonya King (GPA: 3.9)Code:Course.java: import java.util.ArrayList; //create class Student //create class Courseclass Courses{ private ArrayList<Student> roster; // collection of Student object // class constructor…When 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…A. Writing an Interface In this problem you will first write an interface and then modify classes to implement the interface. Write an interface, GeometricSolid, which has one method, volume. The volume method takes no arguments and returns a double. You are provided with three classes: Cylinder, Sphere, and RightCircularCone Modify the classes so that they implement the GeometricSolid interface. Supply the appropriate method for each class. You can use Google search to find the formula for the volume. Make sure that you use Math.PI in your calculations. Notice in InterfaceRunner that the objects are added to an ArrayList of GeometricSolids. since I couldn't fit all images with two screen shots I left the link here link: https://codecheck.it/files/18040616319p6jy6gzkdzuq08nmlp81251t
- 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.Write a class 'Cylinder' that has two fields: height and radius. The class should have only one parameterized constructor function to initialize these fields. The class should also have a method 'getVolume()' to calculate the volume of this cylinder. Now, create any 2 objects of this class with arbitrary values and show their volumes.We have an interface called discount strategy, that calculates discounts for a simple parking management software. It has two sub-classes that implement different discount strategies. 1. DUAffilatedFriday discounts - make discounts for DUAffilated car type on Fridays 2. SUVFriday discounts - make discounts for SUV car type on Fridays These two classes check the car type and day of the week and implement a certain discount strategy. 1. Use a factory pattern to reimplement the entire code as-is. 2. Use a main method to test your code NOte - Use java to write your code Code DiscountStrategy.java import java.time.*; interface DiscountStrategy{public String getStrategyName();public double getDiscount(String CarType, LocalDateTime date);} DUAffilatedFridayDiscounts.java import java.time.*; public class DUAffilatedFridayDiscounts implements DiscountStrategy{ // setting default value of discount to 0.0private double discountPercentage = 0.0;private boolean checkDate(LocalDateTime…