Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!