Consider the following code snippet. public interface Measurable { double getMeasure); } public class Coin implements Measurable { public Coin(double aValue. String aName) {.. } public double getMeasure) { return value; } } public class BankAccount implements Measurable { public BankAccount(double initBalance) { .-- } public void getMeasure( { return balance; } } Which of the following statements is correct? Justify your choice. a) Coin dime = new Coin(0.1, "dime"); BankAccount b = (Measureable)dime; b) Measureable m = new BankAccount(1000); BankAccount b= m; c) Coin dime = new Coin(0.1, "dime"); Measurable m = dime; d) Measurable m = new Coin(0.1, "dime"); Coin dime = m;
Q: An encapsulation violation occurs when private information that should not be changed by external…
A: The given feature Encapsulation is one of the most favorite features of Object-oriented programming…
Q: What is the output of the following code? public interface finalExam { int x = 10; void…
A: The code snippet declares an interface finalExam with x=10 and two abstract methods finalMethod()…
Q: Write a Hamster class that is a subclass of Pet. Include: an additional attributes called…
A: A class is a group of objects which have common properties. A constructor is a method that is used…
Q: Model the world described below by defining proper OOP items (i.e. class, abstract class, interface…
A: Here, Bird will be the Super class and all the remaining classes are subclasses
Q: n JAVA: A subclasss of you bicycle class for a mountain bicycle, as described in the section:…
A: import java.util.*; //Bicycle interface interface Bicycle { abstract void changeCadence(int…
Q: Classes and Objects) Hand-write a complete Java class that can be used to create a Car object as…
A: Program Plan: 1) Create a java class name vehicle. 2) Create Constructor methods/functions :…
Q: Implement the following classes / abstract classes below. Monster abstract class which has health…
A: public class Main { public static void main (String[] args) { //create 3 instances and…
Q: Consider the class Arthropod and the interface Edible as described below: public class Arthropod…
A: Extra functions created for the part 6: public String getSpecies(): it return species value since…
Q: Consider the following code snippet. public interface Measurable { double getMeasure): } public…
A: For the given interface concept program the correct statement is ?
Q: write a Java application that implements different types of insurance policies for employees of an…
A: PROGRAM CODE: // import the required librariesimport java.util.*;// start definition of abstract…
Q: thod
A: Create classes Name, DebitCard and TestClass as per the requirements of the question. In the…
Q: Include the following methods: - A constructor with 3 parameters. Initialize the 3 member variables…
A: Name.java class: public class Name { String firstname,middlename,lastname; public Name(String…
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: 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 an interface as follows: The interface is named ServiceReminder It has one method named…
A: By default interface contains abstract methods. This means that the body of method is not provided…
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: What is the output of the following code? public interface finalExam { int x = 10; void…
A: Hello student. Warm welcome from my side. Hope you are doing great. I will try my best to answer…
Q: Create a Dog and a Cat class, each of which inherit from Animal. Each class should have a…
A: Programs are a set of lines of code that give the machine instructions. To complete those tasks,…
Q: Hand-write two Java classes, Car and Truck. They are bothsubclasses of Vehicle.a. A car has an…
A: Note: Comments have been included in the source code itself to have a better understanding of the…
Q: In java Create an abstract super class called Employee with the following attributes: name :…
A: Hey there, I am writing the required solution based on the above given question. Please do find the…
Q: N JAVA Write a class Store which includes the attributes: store name, city. Write another class…
A: Step 1 The code is given in the below step by step
Q: Consider the following class definition and answer the following question. public class MyClass {…
A:
Q: Assume the class Student implements the Speaker interface from the textbook. Recall that this…
A: HERE IS COMPLETE CODE WITH OUTPUT
Q: It has just one Main class which tests abstract class Animal and its 3 subclasses: Dog, Cat, and…
A: //declaring interfacepublic interface Talker{ //declaring abstract methods public void…
Q: What is the output of the following code? public interface yourInterface { int x = 10, y = 20; void…
A: Interface: Interface in java is abstract type. The methods of interface are implemented by classes.…
Q: Write a Java application that implements different types of insurance policies for employees of an…
A: Actually, the answer has given below:
Q: java Prepare an abstract class SpecialColor with one property the color name (String) and two…
A: The three classes will be created as follows: Class SpecialColor This class has one attribute called…
Q: class Point with instance variables as: xCoordinate(int) and yCoordinate(int). Write public instance…
A: Program code: Filename: Point class(PointClass.java) class PointClass{ private int xCoordinate;…
Q: Consider the following class definition and answer the following questions: public class MyClass {…
A: We need to find the output of the given Java code. MyClass object1=new MyClass(12,15); //This sets…
Q: Implement the following UML Class diagrams. Create several Account objects and a Bank object, then…
A: Given: the Uml diagram, for Account and Bank class: Main class objects:
Q: write all the code necessary for a class Toaster as described here. A toaster can be described as…
A: Introduction: Needs to create a JAVA program with given fields. There should be a default…
Q: In Java Use inheritance to create the class PassengerPlane. An object of this class includes a…
A: Introduction of the Program: The Java Program uses the concept of inheritance. Here the Airplane…
Q: Lab 6 - Exercise 2. Write a test driver that reads data about two surgeons and print the A Doctor…
A: public class Doctor { //declaring data memebers private String name; private int salary;…
Q: n the following statement: public abstract class Vehicle extends DD implements Car{ . . . } DD must…
A: Note: Please note that we are only allowed to solve one question in one post. if you want to get…
Q: A. Write the classes as shown in the following class diagram. Movable is an interface and…
A: Movable.java public interface Movable { void moveUP(); void moveDown(); void…
Q: What is the output of the following code? public interface yourInterface { int x = 10; %3D int y =…
A: Operators are the fundamental building blocks of all programming languages. Java, too, has a variety…
Q: Write a subclass of Account as CheckingAccount. CheckingAccount class will have the additional…
A: Given:-
Q: Given the following superclass: abstract class Shape { private int sides; abstract double…
A: A class is a group of objects which have common properties. A constructor is a method that is used…
Q: Given the following class definition: class Point2d { private int x, y; public Point2d () { x = 0; y…
A: Solution: Given, Point2d.java public class Point2d { private int x, y; public Point2d() { x =…
Q: An encapsulation violation occurs when private information that should not be changed by external…
A: Encapsulation in object-oriented programming usually known as binding the data altogether with the…
Q: Explain the following Java Abstraction code in details and draw the UML notations diagram.
A: Abstraction: It is simply a process of hiding details Like how we made color in Shape class as…
Q: FOR JAVA 1. Implement the following interfaces and classes in Java. Vehicle interface that has has…
A: Vehicle.java ====================== //creating vehicle interfacepublic interface Vehicle {…
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: Implement all the classes using Java programming language from the given UML Class diagram.
A: public class Shape { //declaring instance variables private String color; private boolean filled;…
Q: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
A: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
Q: Write a program in Java that performs the following tasks: Creates a class called Person having…
A: Step 1:- Program Approach:- 1.Create class Person with the attributes personName and personId and…
Q: 1- public class Student { 2 3 public abstract double calcScore(); 4 5 } Which of the following is…
A: The given code is a java code snippet where a Student class is created. The student class has method…
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- *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,…Java program Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance variable, named department, of type String. Supply a method toString that prints the manager’s name, department, and salary. Make a class Executive inherit from Manager. Supply appropriate toString methods for all classes. Supply a test program that tests these classes and methods.Write classes that will extend the given Animal class and optionally implement a leg count interface. (Image attached below, use Java) abstract class Animal { String FUR="fur"; String FEATHER = "feather"; String SCALE = "scale"; String SHELL = "shell"; String SKIN = "skin"; abstract String getCovering( ); abstract void makeSound ( ); abstract boolean canFly( ); } You will need to write: Classes for the animals mentioned above A leg count interface Main method to demonstrate that all of your classes work
- Implement all the classes using Java programming language from the given UML Class diagram. Note: This problem requires you to submit just two classes: Circle.java, Circle.java, Rectangle.java, Square.java. Do NOT include "public static void main()" method inside all of these classes. Write a superclass called Shape (as shown in the class diagram), which contains: Two instance variables color (String) and filled (boolean). Two constructors: a no-arg (no-argument) constructor that initializes the color to "green" and filled to true, and a constructor that initializes the color and filled to the given values. Getter and setter for all the instance variables. By convention, the getter for a boolean variable xxx is called isXXX() (instead of getXxx() for all the other types). A toString() method that returns "A Shape with color of xxx and filled/Not filled". Write a test program to test all the methods defined in Shape. Write two subclasses of Shape called Circle and Rectangle, as…Write a 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) a. Extend a Circle class from Point class such as Class Circle extends Pointb. Write a Default constructor in Circle class that sets radius, xCoordinate & yCoordinate to some default value e.g. -1;c. Write a Parameterized constructor in Circle class which takes xCoordinate, yCoordinate and radius as a parameter.Now write a ColoredCirlce class with private instance variable as color (String) and public setter & getters. Extend the ColoredCircle from Circle and do the following operations.d. Write a default constructor…write all the code necessary for a class Toaster as described here. A toaster can be described as having a model (string), manufacture(string), and price. include the following methods in your class definition.(in java) 1. a default constructor2. an overloaded constructor takes the model and manufacture as input.3. an accessor method to acquire the price.4. a tostring method that returns a reasonable description of the toaster.
- FOR JAVA Implement the following classes / abstract classes below. Monster abstract class which has health point (int), damage point (int), name (String), resistance rate (int) fields and following methods. – A constructor that takes the name as a parameter and sets the health and damage points to random numbers between 10 and 100. – isDead() method which returns true if hp is less than or equal to 0, and false otherwise. – fight() method which prints the applied damage after resistance (see below). WaterMonster class whose resistance rate is %20. For example, if the damage of an instance of this class is 100, the fight method should print 80. FireMonster class whose resistance rate is %10. SlicingMonster class whose resistance rate is %5.Given the following superclass: abstract class Shape { private int sides; abstract double area(); int sides() { return sides; }} Write the following Shape subclasses with the correct instance variables, constructors and area method: (Use Java) Shape sides area rectangle 4 length * width triangle 3 (height * base) / 2 square 4 side * sidewrite program in java Design an abstract class GeometricObject. GeometricObject must ensure that its children must implement calcArea() method. Design RectangleYourRegNo and CircleYourName 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
- Write a 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= 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;…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…URGENT FOR JAVA Implement the following classes / abstract classes below. Monster abstract class which has health point (int), damage point (int), name (String), resistance rate (int) fields and following methods. – A constructor that takes the name as a parameter and sets the health and damage points to random numbers between 10 and 100. – isDead() method which returns true if hp is less than or equal to 0, and false otherwise. – fight() method which prints the applied damage after resistance (see below). WaterMonster class whose resistance rate is %20. For example, if the damage of an instance of this class is 100, the fight method should print 80. FireMonster class whose resistance rate is %10. SlicingMonster class whose resistance rate is %5.