Answered You can hire a professional tutor to get the answer.

QUESTION

How do I run two java files/classes in command prompt if I do not have a package. I will post my two java files below. I have tried javac...

How do I run two java files/classes in command prompt if I do not have a package. I will post my two java files below. I have tried

javac HeadPhone.java && TestHeadPhone.java but it doesnt work

I also tried

Java -cp . HeadPhone && TestHeadPhone

HOW DO I RUN THIS PROGRAM with no IDE please help! :(

 public class HeadPhone {

//Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote theheadphone volume.

  public static final int LOW = 1;

  public static final int MEDIUM = 2;

  public static final int HIGH = 3;

// A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.

  private int volume;

// A private boolean data field named pluggedIn that specifies if the headphone is pluggedin. The default value if false.

  private boolean pluggedIn;

// A private String data field named manufacturer that specifies the name of themanufacturer of the headphones.

  private String manufacturer;

// A private Color data field named headPhoneColor that specifies the color of the headphones.

  private String headPhoneColor;

// no argument constructor that creates a default headphone.

  HeadPhone(){

    volume = MEDIUM;

    pluggedIn = false;

    manufacturer = "DEFAULT";

    headPhoneColor = "DEFAULT";

  }

//  setter method for Volume

  public void setVolume(int v){

    if(v < LOW){

      volume = LOW;

    }

    else if(v > HIGH){

      volume = HIGH;

    }

    else{

      volume = v;

    }

  }

//  setter method for PluggedIn

  public void setPluggedIn(boolean p){

    pluggedIn = p;

  }

//  setter method for Manufacturer

  public void setManufacturer(String m){

    manufacturer = m;

  }

//  setter method for Color

  public void setColor(String C){

    headPhoneColor = C;

  }

//  getter method for Volume

  public int getVolume(){

    return volume;

  }

//  getter method for PluggedIn

  public boolean getPluggedIn(){

    return this.pluggedIn;

  }

//  getter method for Manufacturer

  public String getManufacturer(){

    return this.manufacturer;

  }

//  getter method for Color

  public String getColor(){

    return this.headPhoneColor;

  }

//A method changeVolume(value) that changes the volume of the headphone tothe value passed into the method

  public void changeVolume(int volume){

    setVolume(volume);

  }

//method named toString() that returns a string describing the current field values of the headphones.

  public String toString(){

    return String.format("Volume: %dnPlugged In: %bnManufacturer: %snColor: %s",

        volume, pluggedIn, manufacturer, headPhoneColor);

  }

}

public class TestHeadPhone {

//Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote theheadphone volume.

  public static final int LOW = 1;

  public static final int MEDIUM = 2;

  public static final int HIGH = 3;

// main method to run the program

  public static void main(String args[]){

    //3 HeadPhone objects

    HeadPhones H1 = new HeadPhones();

    H1.setVolume(MEDIUM);

    H1.setManufacturer("BEATS");

    H1.setColor("Red");

    H1.setPluggedIn(true);

    H1.changeVolume(MEDIUM);

    System.out.println(H1+"nn");

    HeadPhones H2 = new HeadPhones();

    H2.setVolume(HIGH);

    H2.setManufacturer("SONY");

    H2.setColor("PINK");

    H2.setPluggedIn(true);

    H2.changeVolume(LOW);

    System.out.println(H2+"nn");

    HeadPhones H3 = new HeadPhones();

    H3.setVolume(MEDIUM);

    H3.setManufacturer("JBL");

    H3.setColor("BLACK");

    H3.setPluggedIn(false);

    H3.changeVolume(LOW);

    System.out.println(H3+"nn");

  }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question