Skip to main content

Need help!

2 replies [Last post]
turismo
Offline
Joined: 2010-01-02
Points: 0

I am following the tutorial on the into to OOP concepts and have altered the code in the examples to come up with this code:

interface Amplifier {

void changeDistortion(int newValue);

void changeVolume(int newValue);

void changeTreble(int newValue);

void changeBass(int newValue);

void printStates();
}

class MS10Amplifier implements Amplifier {

int distortion = 0;
int volume = 0;
int treble = 5;
int bass = 5;

public void changeDistortion(int newValue) {
distortion = newValue;
}

public void changeVolume(int newValue) {
volume = newValue;
}

public void changeTreble(int newValue) {
treble = newValue;
}

public void changeBass(int newValue) {
bass = newValue;
}

public void printStates() {
System.out.println("distortion:"+distortion+" volume:"+volume+" treble:"+treble+" bass:"+bass);
}
}

class AmplifierDemo {
public static void main(String[] args) {

// Create two different Amplifier objects
MS10Amplifier amp1 = new MS10Amplifier();
MS10Amplifier amp2 = new MS10Amplifier();

// Invoke methods on those objects
amp1.changeDistortion(2);
amp1.changeVolume(5);
amp1.changeTreble(8);
amp1.changeBass(6);
amp1.printStates();

amp2.changeVolume(5);
amp2.changeTreble(4);
amp2.changeBass(6);
amp2.printStates();
}
}

It compiles fine but then when I try to run it, I get this error:

Exception in tread "main" java.lang.NoSuchMethodError: main

What is wrong with my code? All help is greatly appreciated!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zfsk
Offline
Joined: 2010-02-12
Points: 0

hi
your code is fun just your file must be have this name AmplifierDemo.java
good luck for any help do not hesitate

lucasvieites
Offline
Joined: 2005-05-27
Points: 0

Hi,
all I can think of is that your CLASSPATH variable is not set up correctly.
Can you try to do "unset CLASSPATH" and try again?

Cheers,