Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package amplifiersapp; import java.util.ArrayList; public class AmplifiersApp { / * * * @param args * / public static void main ( String [ ] args

package amplifiersapp;
import java.util.ArrayList;
public class AmplifiersApp {
/**
* @param args
*/
public static void main(String[] args){
double r1=4;
double r2=20;
ArrayList amplifiers = new ArrayList();
amplifiers.add(new InvertingAmplifier(r1, r2));
amplifiers.add(new NoninvertingAmplifier(r1, r2));
amplifiers.add(new VdivAmplifier(r1, r2));
for (int i =0; i < amplifiers.size(); i++){
System.out.println(amplifiers.get(i).getDescription()+"
"
+ "Gain: "+ amplifiers.get(i).getGain());
}
}
public abstract class Amplifier {
double R1, R2;
public Amplifier(double R1, double R2){
this.R1= R1;
this.R2= R2;
}
public abstract String getDescription();
public abstract double getGain();
}
public class VdivAmplifier extends Amplifier {
public VdivAmplifier(double R1, double R2){
super(R1, R2);
}
@Override
public String getDescription(){
return "Vdiv Aplifiers: R1="+ R1+" R2="+ R2;
}
@Override
public double getGain(){
return ((R2)/(R1+R2));
}
}
public class NoninvertingAmplifier extends Amplifier {
public NoninvertingAmplifier(double R1, double R2){
super(R1, R2);
}
@Override
public String getDescription(){
return "Noninverting Aplifiers: R1="+ R1+" R2="+ R2;
}
@Override
public double getGain(){
return 1+(R2/R1);
}
}
public class InvertingAmplifier extends Amplifier {
public InvertingAmplifier(double R1, double R2){
super(R1, R2);
}
@Override
public String getDescription(){
return "Inverting Aplifiers: R1="+ R1+" R2="+ R2;
}
@Override
public double getGain(){
return (-(R2/R1));
}
}
}
I am getting this error error: non-static variable this cannot be referenced from a static context
amplifiers.add(new InvertingAmplifier(r1, r2));
Also public static void main(String[] args){
double r1=4;
double r2=20;
ArrayList amplifiers = new ArrayList();
amplifiers.add(new InvertingAmplifier(r1, r2));
amplifiers.add(new NoninvertingAmplifier(r1, r2));
amplifiers.add(new VdivAmplifier(r1, r2));
for (int i =0; i < amplifiers.size(); i++){
System.out.println(amplifiers.get(i).getDescription()+"
"
+ "Gain: "+ amplifiers.get(i).getGain());
}
}
this needs to be unchanged

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Identify conflict triggers in yourself and others

Answered: 1 week ago