class Garden{ private int area; public Garden(int a) { area = a; } public boolean equals (Garden g) { if (g1.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 (g1==g2) System.out.print("AAA"); else if (g1.equals (g2)) System.out.print("BBB"); else System.out.print("CCC"); }
Q: The following code is valid in Java: public abstract class Shape ( private String name; public…
A: The given code in Java will not work. Therefore, the correct is False.
Q: Write a Java class Person for dealing with persons. Your class must have the following features:…
A: As per the requirement person class is developed. Note: As per our guidelines we are suppose to…
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: public class BClass { private int x; public void set(int a) { x = a; } public void print( {…
A: print() method displays the respective data member of the class. In method overriding, we need to…
Q: Write a Java class Person for dealing with persons. Your class must have the following features:…
A: class Person{ long person_id; String name,gender; //default constructor Person(){…
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: class Garden{ private int area; public Garden (int a) { area = a; } public boolean equals (Garden g)…
A: Ans: Code: class Garden{ private int area; public Garden(int a){ area = a; }…
Q: iven a Card class, implement a subclass called IDCard class. public class Card
A: public class Card { private String name; public Card(String n) { this.name = n; }…
Q: A Java program to demonstrate use of Comparable
A: Name.java public class Name implements Comparable<Name> { private String first; private String…
Q: Collection of classes performing similar task is grouped in java language as
A: Here, Fill in the blank is given.
Q: public Object equals(Object obj)
A: The correct answer of the questions is option "TRUE"
Q: This composition example contains classes Date, Employee and EmployeeTest .Class Date declares…
A: This composition example contains classes Date, Employee and EmployeeTest .Class Date declares…
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: 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: 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: For example, 1.Input: ["Once","a","upon","time"], Output: ["Once","a","time","upon"] 2.Input:…
A: According to the information given:- We have to follow the instruction mention to obtain desired…
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: 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: # 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: 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: 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: public abstract class Landmark { public abstract int countVisitors(); } Consider the class shown…
A: Data Abstraction is an OOP concept that hides the background details. It shows only those…
Q: Write a Rectangle class. Its constructor should accept length and width as a parameter. It should…
A: Answer has been explained below:-
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: 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: Given the following class: public class Student { private long ID; private String name;…
A: Programming instructions: Create a Student class. Create variables. Create constructor without…
Q: The play method in the Player class of the craps game plays an entire game without interaction with…
A: Given data, The play method in the Player class of the craps game plays an entire game without…
Q: A shuttle van picks up passengers and drives them to a destination, where they leave the van. Keep a…
A: PROGRAM EXPLANATION: - The Van class comprise of three instance variables namely maxPassengers,…
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: public class Tire{ } public abstract class Vehicle {} public abstract class LandVehicle extends…
A: in line B, Vehicle is an abstract class, so it cant be instantiated, so this line will not work. in…
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: A complex number has two parts: real value and imaginary value. In mathematics, we learnt how to add…
A: Answer: Code : Code : class Complex { int real, imaginary; // Default constructor…
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: 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: Consider the following class public class Ketchup extends Food implements Tasty{ public String…
A: Imрlements meаns yоu аre using the elements оf а Jаvа Interfасe in yоur сlаss. extends…
Q: public abstract class Bird { private int x; private int y; private int z; public void…
A: The solution for the above given question is given below:
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:
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:
What is the output for the following java code?
Step by step
Solved in 2 steps
- 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();}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 =…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...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*lengthpackage 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); } }…
- 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…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};…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…Course Title: Modern Programming Language Please Java Language Code Question : Design an abstract class GeometricObject. GeometricObject must ensure that its children must implement calcArea() method. Design Rectangle18-ARID-2891 and CircleM.JibranAkram Classes as children of GeometricObject class with overridden toString() method to return “Rectangle with w Width and h Height is drawn” OR “Circle with r Radius is drawn”. The attributes of Rectangle are length, width. The attribute of Circle is radius Hint: Area of circle=πr2 , Area of rectangle= width*length