JAVA - Abstraction and Encapsulation are one pillar of OOP (Object Oriented Prog
ID: 3684584 • Letter: J
Question
JAVA -
Abstraction and Encapsulation are one pillar of OOP (Object Oriented Programming). Another is inheritance and polymorphism. In this assignment we will use inheritance and polymorphism to solve a problem.
Part (a) of the figure below shows a symbolic representation of an electric circuit called an amplifier. The input to the amplifier is the voltage vi and the output is the voltage vo. The output of an amplifier is proportional to the input. The constant of proportionality is called the “gain” of the amplifier.
Parts (b), (c), and (d) show schematics of three specific types of amplifier: the inverting amplifier, non-inverting amplifier, and voltage divider amplifier. Each of these three amplifiers consists of two resistors and an op amp. The value of the gain of each amplifier depends on the values of its resistances. In particular, the gain, g, of the inverting amplifier is given by
Similarly, the gains of the non-inverting amplifier and voltage divider amplifier are given by
Write a Java program that represents the amplifier as a superclass and represents the inverting, non-inverting, and voltage divider amplifiers as subclasses. Give the subclass two methods, getGain and a getDescription method that returns a string identifying the amplifier. Each subclass should have a constructor with two arguments, the resistances of the amplifier.
The classes need to override the equals, hashcode, and toString method from class object.
The subclasses need to override the getGain and getDescription methods of the superclass. Create a class with a main
method that contains a generic data structure of type Amplifier. Iterate over the structure and display the gain, description,
and toString methods to show that the subclasses all work properly for sample values of the resistances.
Demonstrate that the equals method works for all subclasses.
R1 (a) Amplifier (b) Inverting amplifier (c) Noninverting amplifier (d) Voltage divider amplifierExplanation / Answer
Hi below i have written the sample code for your reference,
public class Amplifier
{ private int r1; private int r2; /** * Constructs an operational Amplifier * @param resistance1 the first resistance * @param resistance2 the second resistance */ public Amplifier( int resistance1, int resistance2) { r1 = resistance1; r2 = resistance2; } /** * Gets the first resistance * @return the first resistance */ public int getR1() { return r1; } /** * Gets the second resistance * @return the second resistance */ public int getR2() { return r2; } /** * Set a new value for the first resistance * @param resistance the new resistance */ public void setR1(int resistance) { r1 = resistance; } /** * Set a new value for the second resistance * @param resistance the new resistance */ public void setR2(int resistance) { r2 = resistance; } /** * Gets the gain for this amplifier circuit * @return the gain */ public double getGain() { return 0; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.