Say I create a superclass Bird, a subclass Parrot extends Bird, and a subclass Parakeet extends Parrot. Say I write a method like "public static void printName(Bird b)" to print the name of the bird. If I send a Parakeet object into the parameter, will any error occur? I know a Parakeet is-a Bird.
Q: Write a resource class that has the deposit, withdrawal, and print balance methods. Next, implement…
A: ## As no programming language is mentioned, the code is written in Python. class Resource:…
Q: Suppose the class SportsCar is a derived class of a class Automobile,and suppose also that the class…
A: PARENT CLASS: Automobile Methods: accelerate, addGas DERIVED CLASS: SportsCar
Q: Write a program in java . Create a class names “A” with a method to print “ method of class A”. •…
A: Java is an Object Oriented Programming language which provides Inheritance where Child classes can…
Q: Consider the class Point2D2310 below that represents a point in a 2 dimensional environment.…
A: The changes in Point2D2310 is highlighted Point2D2310.java public class Point2D2310 { private int…
Q: Set the last name only. Set the first name only. Set the middle name. Check whether a given last…
A: Note: Since you have not provided the language to write the code so I am using java language to…
Q: In java How to compare two objects in java? for example :- take one number of long type and other…
A: approach :- given two numbers and you have to create two object of double and long class with…
Q: Implement a superclass Father that Make two classes, Boy and Girl that inherit from Father. A Father…
A: Java used to answer this question
Q: Redefine the equals method of the class Date (Display 4.13) so that it hasa parameter of type Object…
A: Redefine the equals method of the class Date (Display 4.13) so that it hasa parameter of type Object…
Q: Implement a class, called Combination, to store four integer values (ints). 1. Declare the necessary…
A: Question:
Q: Write a Java enumeration LetterGrade that represents letter grades A through F, including plus and…
A: Answer : /************************************** *The following LetterGradeDemo class class…
Q: In this exercise, you are going to build on your Circleclass from the previous exercise. You are…
A: Modification to be done in the program: To add the areaDifference() method that returns the…
Q: Consider a class that could be used to play a game of hangman. The class has the following…
A: Note - As per the guidelines we're only allowed to answer 1 question at a time. Define a main…
Q: Python: implement a class called point, the class contains two values of a type of integer (x and…
A: The main objective of the program is to create a point class. The point class has two variables x…
Q: Implement a class clock whose getHours and getMinutes methods return the current time at your…
A: LocalTime class in java API (Application Programming Interface) is in java. time package. The…
Q: For this exercise, you will be completing the Account class, which simulates a regular bank account,…
A: Given, For this exercise, you will be completing the Account class, which simulates a regular bank…
Q: In this problem, we are going to use ArrayLists and classes to design a road trip. You have three…
A: Actually, Java is a programming language originally developed by James Gosling at Sun Microsystems…
Q: Implements an interface having three methods eat, travel, bark in class ANIMAL having three child…
A: Program Plan: Create an interface named Animal In that interface declare methods…
Q: Implement a Python class for the Tweet ADT with an instance variable for storing the text and a…
A: Python program to solve the given problem.
Q: Q2. Imagine you have two classes: Employee (which represents being an employee) and Ninja (which…
A: CODE:- import java.util.*;import java.io.*;interface Check{int S=0; //statepublic void…
Q: Consider the class shown in the image below. D "Student java 13 1. 2 public class Student ( private…
A: A class is a group of objects which have common properties. A constructor is a method that is used…
Q: Are the fields in the following interface class fields or instance fields? public interface Quiz {…
A: Interface is like the blue print of the class. If any particular method has no defination at the…
Q: Write a class named NameAndCount for recording a String data name and an int data named count. A…
A: The NameAndCount class implements a Comparable interface. An interface is a class that contains the…
Q: ontainsInRange. This class defines a method called contains(), which takes as parameters an integer…
A: Create class ContainsInRange. Define method contains to check the value x in array a in the range…
Q: Suppose we define a method as follows: public void foo(List input) { } Which of the following do we…
A: Dear learner, hope you are doing well , I will try my best to answer this question. Thank You!!
Q: Write a ThreeWayLamp class that models the behavior of a lamp that uses a three-way bulb. These…
A: Given: Write a ThreeWayLamp class that models the behavior of a lamp that uses a three-way bulb.…
Q: In this exercise, you are going to build on your Circleclass from the previous exercise. You are…
A: public class Circle { private double radius; public Circle(double theRadius) { radius =…
Q: What methods are polymorphic in the Employee Hierarchy? How could we build a method like…
A: The classes Employee, SalariedWorker, HourlyWorker are given below: /* * Employee.java - Abstract…
Q: Create a Java Project (with a class and a test class) to represent some real-world entity such as a…
A: The complete answer in Java Programming Language is below: we are taking example of person.
Q: Create a class Hotel with member data, hotel name and category (number of stars). For the Hotel…
A: The main objective of the program is to create Hotel.java and a test java program, TestHotel.java to…
Q: Consider a class PersonAddress that represents an entry in an address book. Its attributes are • The…
A: Programming is a way to instruct the computer devices to operate. Every computer needs a set of…
Q: Write a java class called House with the following two private attributes, and three methods:…
A: The classes House and HouseMap are given below and their formatted image version: public class…
Q: Write a Java program for a class called MyPoint, which models a 2D point with x and y coordinates,…
A: A class called MyPoint, which models a 2D point with x and y coordinates, is designed as shown in…
Q: What will be the output of the following code? interface Test { int x = 10; } public class MyClass…
A: Given, Java code: interface Test {int x = 10;}public class MyClass implements Test{public void…
Q: Consider the following code. Replace the tags_??1_and_??2_, respectively, by filling in the text…
A: Question 1: _??1 : foo Explanation: If two interfaces contain a method with the same signature…
Q: Create a Java Project (with a class and a test class) to represent some real-world entity such as a…
A: We'll use a real-world animal to fulfill all of the conditions.
Q: Lets say that class Laptop has been implemented. In order to compare two laptops a compareTo method…
A: The answer of this question is as follows:
Q: Using JAVA Language Consider a Billing class that implements an interface Payable having a method…
A: Solution: //java Program: //Doctor.java //class Doctorpublic class Doctor { // Declaring Instance…
Q: For this exercise, you will be completing the Account class, which simulates a regular bank account,…
A: LOGIC: The given problem will have below three classes: a) Account.java: A base class to hold…
Q: Build a class called BankAccount that manages checking and savings accounts
A: Use another print method to print all values and test the above by creating an instance
Q: Write a java program with the class name Vehicle. The class has three instance variables with names…
A: Basically, three classes are implemented. The Vehicle class is the base class and the Bus class is…
Q: Write a class named NameAndCount for recording a String data name and an int data named count. A…
A: The interface is a class that contains the declarations of the methods and the definition of the…
Q: In Java, please. Complete the Course class by implementing the findStudentHighestGpa() method,…
A: The solution for the above given question is given below:
Q: 1/ Write a BankAccountTester class whose main method constructs a bank account, deposits $1,000,…
A: 1. BankAccountTester.java public class BankAccountTester { public static void main(String…
Q: Write a ThreeWayLamp class that models the behavior of a lamp that uses a three-way bulb.These bulbs…
A: #include "demo.h" void ThreeWayLamp::main(std::vector<std::wstring> &args) {…
Q: What is the output of the following code where Student is a subclass of Person class? Person s = new…
A: The answer varies acccording to type of class
Q: Write a complete Java class that can be used to create a Fish object as described below: A Fish…
A: public class Fish{ //Data members private String name; private int age; private String…
Say I create a superclass Bird, a subclass Parrot extends Bird, and a subclass Parakeet extends Parrot. Say I write a method like "public static void printName(Bird b)" to print the name of the bird. If I send a Parakeet object into the parameter, will any error occur? I know a Parakeet is-a Bird.
Step by step
Solved in 3 steps with 5 images
- The following is a class definition for a simple Ebook. Two instance variables and one parameterless constructor are provided. Part 1: Write a second constructor that takes a String array of pages as input and sets the String array instance variable equal to the input. Continue to default the current page number to zero. Part 2: Write a getter and a setter method for the page number variable. The setter should check to make sure that the input is a valid page number and only update the variable if the new value is valid. Part 3: Write a getCurrentPage method that returns the String of the current page indexed by current_page. public class Ebook{ private String[] pages; private int current_page; //constructor public Ebook() { this.pages = {"See Spot.", "See Spot run.", "Run, Spot, run."}; this.current_page = 0; }}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:…Write a complete program for the description given below. Consider a Billing class that implements an interface Payable having a method getTotalPayment Amount(). Besides this, you have a Doctor class with private instance variables (docID, docName, and docFee) and a public getDoc() method, Patient class with private instance variables (pName, pID. pDisease), Medicine class with private instance variables (medID, medName, medQty, medPrice), and Medical Test class with private instance variables (testID, testName, testPrice). Each of these classes has the toString() method to display the information of its object. The Billing class is having "Has A" relationship with the other four classes (Doctor, Patient, Medicine, and MedicalTest) mentioned above. The getPayment Amount() method of Billing class returns the total billing amount that includes doc fee, medicine cost, and medical test fee that a patient has to pay. After implementing these classes, you are required to do the following in…
- ANSWER IN JAVA 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.Assume B is a subclass of A. Which of the statements about the following assignment is false? A a = new B(); We can assign anything to variable a that has a subtype of B. We can call on a any method defined in A. We can call on a any method defined in B. We can assign anything to variable a that has a subtype of A.box1 and box2 are instances of the Box class. Attributes length, width, and height of both box1 and box2 are read from input. Then, two strings are read from input. In the Box class, define instance method print_measurements() with self and one string as parameters to output the string parameter in one line, and the following in the next line: The value of attribute length ' by ' The value of attribute width ' by ' The value of attribute height
- 1. Write a java class called Pokemon that has a name (e.g. “Pikachu”) and a number (e.g. 25). Implement a constructor that takes both values as parameters. Implement accessors for both values. Implement a toString() that returns a string in the format “Name(number)”, e.g. “Pikachu(25)”. Implement an equals(Object) method (two Pokémon are considered equal if they have the same number). Implement a hashCode() method that returns the number. (remember the equals and hashCode contract). 2. Create a java class, PokemonComparator, that implements Comparator and compares two Pokémon in reverse order by number. For example, if Pokemon A's number is 25 and B's number is 50, compare(A, B) would return a number > 0 because B should come first. Hint: what if you subtracted the numbers? 3. Write a new class, PokemonMain, with a main method that: a. Creates a binary tree with your favorite Pokémon at the root and a new PokemonComparator. b. Insert at least 10-15 more Pokémon in any order. c.…Write a java class method named capitalizeWords that takes one parameter of type String. The method should print its parameter, but with the first letter of each word capitalized. For example, the call capitalizeWords ("abstract window toolkit"); will produce the following output: Abstract Window Toolkit1/ 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…
- in JAVA Assume that a receipt id contains characters that represent information or that can be used as a code to determine something about the purchase. For example: if an id has an 'x' followed by two 'y's, it means that the purchase was a final sale and cannot be returned. Or if an id has an 'a' followed by three 'b's, it means that a coupon was used for purchase. Write a static method for the Receipt class to test whether a receipt id meets such a criteria. Does the id meet the criteria? The criteria is described by three pieces of data, passed in as parameters: char firstTarget char second Target int countOfSecond After First A receipt id meets the criteria if: the id contains the first target character and the second target character appears exactly the specified number of times after the first target character appears Note: the first and second char could be the same char! Carefully review the provided driver program for examples of ids that meet and don't meet criteria. For full…I need help with: The following is a class definition for a simple Ebook. Two instance variables and one parameterless constructor are provided. Part 1: Write a second Java constructor that takes a String array of pages as input and sets the String array instance variable equal to the input. Continue to default the page number to zero. Part 2: Write a getter and a setter Java method for the current page number variable. The setter should check to make sure that the input is a valid page number and only update the variable if the new value is valid. Part 3: Write a getCurrentPage method that returns the String of the current page indexed by current_page. public class Ebook { private String[] pages; private int current_page; //constructor public Ebook() { this.pages = {"See Spot.", "See Spot run.", "Run, Spot, run."}; this.current_page = 0; } }Write a java program to create a class Rectangle. The class has attributes Length andWidth. It should have methods that calculate Area and Perimeter of the Rectangle.Each set method for length and width should verify that length and width are doublepoint numbers larger than 0 and less than 50. Each get method shows the values oflength and width. Write a class TestRectangle to test the class Rectangle. In theTestRectangle, each method of Rectangle class needs to be called with the inputentered from screen and display the results.