class Garden{ private int area; public Garden (int a) { area = a; } public boolean equals (Garden g) { if (gl.area==g2.area) return true; else return false; } } public class MyClass { public static void main (String[] args){ new Garden (127); = new Garden (127); Garden gl Garden g2 if (gl==g2) System.out.print ("AAA"); else if (g1.equals (g2)) System.out.print ("BBB"); else System.out.print ("CCC"); }
Q: Your task is to implement the following Product class. The description of the class is as follows:…
A: In this question we have to write the JAVA code with the given implementation list. Where, we have…
Q: class Garden{ private int area; public Garden(int a) { area = a; } public boolean equals (Garden g)…
A: In the following code A garden class is there with area private variable and garden constructor,…
Q: UML Diagrams: Course -courseName: String -students: Student [] -numberOfStudents: int…
A: There is only one constructor in the Course. +Course(courseName : String) It is a parameterized…
Q: Data Structure Add three methods to the following class
A: The static method add() takes two polynomials p1 and p2 as parameter. It finds the max matching…
Q: Question : Design an abstract class GeometricObject. GeometricObject must ensure that its children…
A: Program: Programs are generally used to interact with computer systems. The main objective of the…
Q: A GradeBook Example : In this example ,GradeBook class has one attribute and some methods to access…
A: Algorithm: Add marks and totalStudents variables in class. Add corresponding getter and setter…
Q: Collection of classes performing similar task is grouped in java language as
A: Here, Fill in the blank is given.
Q: public class Ice extends Fire { public void method1() { System.out.print("Ice 1 "); public class…
A: Output of the given program is given below:-
Q: I wonder how can i whrite the method show(). C++ write a constructor with parameters and a new…
A: #include <iostream>#include<string>using namespace std; class Address{ public:…
Q: public class Team { private String name; private int wins, int losses; public…
A: Program Approach: In the given code a class "Team" is declared that defines one string "name"…
Q: package wednesdayClass; class Wuntumi{ private double salary; private String name; private float…
A: Please give positive ratings for my efforts. Thanks. ANSWER The reason for the incorrect code is…
Q: The class diagram below shows an Order class that "has a" Customer and zero or more Items. Order…
A: The class diagram below shows an Order class that "has a" Customer and zero or more Items. Order…
Q: Use java programming language 1.1 Create a Student Object project. Create a Student class and use…
A: Student.java =================== import java.util.Random; public class Student { //declare variables…
Q: Course Title: Modern Programming Language Please Java Language Code Question : Design an abstract…
A: Circle.java public class Circle extends GeometricObject { private double radius; public Circle()…
Q: reate a random player that can make valid random moves. Extend the base class Player to create a…
A: Given: Create a random player that can make valid random moves. Extend the base class Player to…
Q: the blank in the main method. public class Min { //define your static method here } Write a static…
A: In this question we have to complete the given method in the Java code. For the method where it will…
Q: in java A class Book is designed to model a book written by one author. It contains: Four private…
A: //Driver code import java.util.*; public class Main { public static void main(String[] args) {…
Q: write a java program This composition example contains classes Date, Employee and EmployeeTest…
A: Given: Class EmployeeTest creates two Date objects to represent an Employee’s birthday and hire…
Q: java programming Complete the code for the class StudentAccount in the following. Add constructors…
A: The abstract class is the class in which abstract classes can't be created object and if the class…
Q: RITE IN JAVA PROGRAMMING LANGUAGE: Given a field school in a class declared as: private College…
A: The answer is given below.
Q: Look at the following class declarations: class Plant { public virtual void Message() {…
A: OUTPUT: - I'm a tree. It is an example of Method overriding. The object of the Tree class is…
Q: b) a) public abstract myClass ( int result-01 public void add(int x, int y) ( result x + y; } public…
A: The question is to write corrected code for the given code segments.
Q: # Coding - Simulate a robot Write a program that simulates the movements of a robot. The robot can…
A: Let G - advance L- turn left R- Turn right
Q: magine a publishing company that markets both book and audiocassette versions of its works. I it…
A: code in c++
Q: The BankAccount class models changes to the balance of a person’s savings account.
A: import java.util.Scanner; public class Bank { public static void main(String[] args) {…
Q: class A{ protected: int x, y; public: int z; }; class B: private A{ private: int a, b, c; public:
A: a) B have 6 data members. They are x,y,z,a,b,c b) No data members are visible in B. c) x,y,z,a,b,c…
Q: 5 Select one or more options from the list cat.getAge(); O cat.getName(); cat.getColor();…
A: Explanation: I have created a main class to for compiling this program, The methods that are in…
Q: Given the following code: } public class Foo { public void barl () { public abstract void bar2 ();…
A: abstract method Only applicable in an abstract class, an abstract method lacks a body. The subclass…
Q: * Constructor for objects of class SimpleBankAccount public SimpleBankAccount (){ balance- 0.0; ac…
A: Given that:
Q: public void addRoom (String type, double area) m rooms [m countRooms] m countRooms++; = new Room…
A: IN this question we have to demonstrate the relationship between the following classes in java.
Q: Pet Whisperer Define a public class Whisperer that provides a single class method named…
A: Java Code for Above : //class in which method is defined class Whisperer{ //method…
Q: ln OOP perspective, it is nothing but an instance of a class that contains real values instead of…
A: The instance of Object-oriented programming OOPs is the specific realization of an object that may…
Q: Assume the Book class is defined as follows: public class Book{ enum Type type…
A: The Book class is defined as follows: public class Book{ enum Type type {FICTION,NON_FICTION};…
Q: (Rectangle Class) Create a class Rectangle with attributes length and width, each of which defaults…
A: Here, you need to create class called 'Rectangle' with attributes length and width. In this class,…
Q: -Interface IResearchScholar has two methods: public void teaches (string str) and public void…
A: java programing in string: A string in Java is a sequence of characters. For example, "hello" is a…
Q: Write a class Point for 2D Cartesian co-ordinates. The class should have 2 fields: abscissa(x) anc…
A: As mentioned in the question im writing a class point for 2D Cartesian co-ordinates
Q: UML for the following Code: public class ProductOrder { private int numBook = 0; private…
A: Answer: We have written UML diagram for given following code
Q: Class : HumanBeing Main Class: Index private public setHeight() 1. call the Human height being…
A: Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that…
Q: tumLeft and turn Right methods that change the direction of the robot but not the location move…
A: public class Robot{ //declaring instance variables private String name; private int xPos; private…
Q: JAVA class: Main.java, Quadratic.java, TestQuadratic.java Create a class called Quadratic for…
A: The roots of the quadratic equation in the form of ax2+bx+c=0 can be calculated using the below…
Q: Consider the following class definition: public class MyClass private int value; public void set…
A: Answer: Given Code is: public class MyClass { private int value; public void setValue(int i){ }
Q: Complete the Kennel class by implementing the following methods: addDog(Dog dog) findYoungestDog()…
A: Add the dog at the end of the array in addDog method In findYoungestDog method, we need to iterate…
Q: WRITE THE OUTPUT OF THE PROGRAM AND WRITE THE UML DIAGRAM OF THE PROGRAM : JAVA
A: Output: Item Number:112Name: BookQuantity: 3Price: 125.98Total Cost: 0.0Item Number:101Name:…
Q: Create abstract class Ticket, and classes TrainTicket and PlaneTicket. Define all attributes and…
A: We need to implement the : Ticket.java TrainTicket.java PlaneTicket.java as per the given…
Q: What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle");…
A: Option A: Syntax error
Q: True or False, the below method is a good example of a toString() method for the below class: public…
A: In second step all the explain the all data member and method to the override.
Q: Perceptron.java: Implement the Perceptron constructor, Perceptron(int n), and the method, int…
A: public class Perceptron{ int n; //constructor Perceptron(int n){ this.n=n; } //no. of inputs…
Q: Subject(String subjectStr) { subjectName = subjectStr; } %3D public String returnSubjectstr() {…
A: Find the answer given as below : As this is pseudo code there is no output:
Q: Write a class Student with the following attributes (make sure the attributes are private using name…
A:
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:
please solve it
Step by step
Solved in 2 steps
- JAVA A Matryoshka, or Russian nesting doll is either solid or hollow. If it is hollow, it contains another doll (which can also be hollow or solid). Given the supplied Doll class, implement a recursive method named show that returns a String representing the chain for dolls, for example Natasha contains Tanya contains Peter public class Doll{ private String name; private Doll dollInside; /** * Constructs a hollow doll with the doll it contains. */ public Doll(String theName, Doll theDoll) { name = theName; dollInside = theDoll; } /** * Constucts a solid doll. */ public Doll(String theName) { name = theName; dollInside = null; } public boolean isSolid() { return dollInside == null; } public String getName() { return name; } public Doll getDollInside() { return dollInside; }} public class DollViewer{ public static String show(Doll d) { /* code goes here */ } public static void main (String [] args) { Doll dolls1 =…Go off this code: public abstract class Employee{private String firstName;private String lastName;private String SSN;double salary; public Employee( String first, String last, String ssn ){firstName = first;lastName = last;SSN = ssn;} public void setfirstName( String first ){firstName = first; // should validate} public String getfirstName(){return firstName;} public void setlastName( String last ){lastName = last; // should validate} public String getlastName(){return lastName;} public void setSSN( String ssn ){this.SSN = ssn;}public String getSSN(){return SSN;} @Overridepublic String toString(){return String.format( "%-12s%-12s%-12s", getfirstName(), getlastName(), getSSN() );}public abstract double earnings();}public class Team { private String name; private int wins, int losses; public Team(String n, int w, int l) { name = n; wins = w; losses = l; } public void setName( String n) { name = n; } public String getName() { return name; } } How many constructors are there in the TEAM class? a. 0 b. 1 c. 2 d. 3
- Polymorphism in Java In the class “Phone”, there is a method call() which in default prints “Calling Emergency services…”. Override this method by accepting a string called number. Accept for a number as input. If input is 0, call the default method. Inputs 1. A string 1234567 Sample Output Enter number: 1234567 Calling number 1234567...package lab1; /** * A utility class containing several recursive methods * * <pre> * * For all methods in this API, you are forbidden to use any loops, * String or List based methods such as "contains", or methods that use regular expressions * </pre> * * */ public final class Lab1 { /** * This is empty by design, Lab class cannot be instantiated */ privateLab1(){ // empty by design } /** * Returns the product of a consecutive set of numbers from <code> start </code> * to <code> end </code>. * * @param start is an integer number * @param end is an integer number * @return the product of start * (start + 1) * ..*. + end * @pre. * <code> start </code> and <code> end </code> are small enough to let * this method return an int. This means the return value at most * requires 4 bytes and no overflow would happen. */ publicstaticintproduct(ints,inte){ if(s==e){ returne; }else{ returns*product(s+1,e); } }…Course Title: Modern Programming Language Please Java Language Code and Correct Code Please Question : Design an abstract class GeometricObject. GeometricObject must ensure that its children must implement calcArea() method. Design Rectangle18ARID2891 and CircleMJibranAkram Classes as children of GeometricObject class with overridden toString() method to return “Rectangle18ARID2891 with w Width and h Height is drawn” OR “CircleMJibranAkram with r Radius is drawn”. The attributes of Rectangle18ARID2891 are length, width. The attribute of CircleMJibranAkram is radius Hint: Area of circle=πr2 , Area of rectangle= width*length
- Assume the Book class is defined as follows: public class Book{ enum Type type {FICTION,NON_FICTION}; public int isbn; public Type type; Book(int isbn, Type type){ this.isbn = isbn; this.type = type; }} Define filterBooksOfGivenType method that shall return ArrayList of Book of the type specified in parameter.NEED HELP WITH JAVA PROGRAM PLEASE HELP THANK YOU . -ERROR SEE IMAGE BELOW Cake.java public abstract class Cake{protected String name;protected double rate;protected double calcPrice;public Cake(String n, double r){name = n;rate = r;}public abstract double calcPrice();public String toString(){return name + "\t" +rate;}}class orderCake extends Cake{double weight;public orderCake(double weight,String n, double r){super(n,r);this.weight= weight;}public double calcPrice(){return rate * weight;}}class readymadeCake extends Cake{double quantity;public readymadeCake(double quantity,String n, double r){super(n,r);this.quantity= quantity;}public double calcPrice(){return rate * quantity;}} TestCakeProgram.java import java.util.Scanner;class TestCakeProgram{public static void main(String args[]){Scanner sc= new Scanner(System.in);int choice=0;System.out.println("ENTER RATE FOR ORDERED CAKE: ");double rate0=sc.nextDouble();System.out.println("ENTER RATE FOR READYMADE CAKE: ");double…import java.util.*; public class Car implements Comparable<Car>{ private int m_inventory; // the number of cars of this make/model private String m_make; // the make of a car private String m_model; // the model of a car // Creates a new car. // This takes the inventory as a String but the inventory is // stored in the class as an integer. As a result, you must // convert the inventory to an integer. // This Should also set inventory to 0 if the inventory passed // is not a valid integer. public Car(String inventory, String make, String model) { // TODO: Part 6 - use a try/catch to set inventory to 0 // if the inventory is not a valid integer m_inventory = Integer.parseInt(inventory); m_make = make; m_model = model; } // Returns the inventory of cars of this make/model. public int getInventory() { // TODO: Part 1 } // Increases the inventory by one. public void…
- class 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;…Following is the class of Person: public class Person { private String Name; public int age; public void set(String Name, int age) { this.Name = Name; if(age > 0 && age <= 100) this.age = age; else this.age = 1; } public void display() { System.out.println("Name: " + this.Name +" ,Age: " + this.age); } public static void main(String[] args) { PersonManagement personManagement = new PersonManagement(); Person p1 = new Person(), p2 = new Person(), p3 = new Person(), p4 = new Person(), p5 = new Person(); p1.set("Asad", 103); p2.set("Ali", 17); p3.set("Usman", 16); p4.set("Raees", 18); p5.set("Mujeeb", 15); Person[] persons = new Person[]{p1,p2,p3,p4,p5};…*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,…