Skip to main content
Code Review

Return to Question

Bumped by Community user
deleted 16 characters in body
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

 Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.

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

 A private boolean data field named pluggedIn that specifies if the headphone is plugged in. The default value is false.

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

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

 A private String data field named headPhoneModel that specifies the Model of the headphones.

 getter and setter methods for all data fields.

 A no argument constructor that creates a default headphone.

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

 A method named changeVolume(value) that changes the volume of the headphone to the value passed into the method

  • Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.

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

  • A private boolean data field named pluggedIn that specifies if the headphone is plugged in. The default value is false.

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

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

  • A private String data field named headPhoneModel that specifies the Model of the headphones.

  • getter and setter methods for all data fields.

  • A no argument constructor that creates a default headphone.

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

  • A method named changeVolume(value) that changes the volume of the headphone to the value passed into the method

Please help.

 Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.

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

 A private boolean data field named pluggedIn that specifies if the headphone is plugged in. The default value is false.

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

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

 A private String data field named headPhoneModel that specifies the Model of the headphones.

 getter and setter methods for all data fields.

 A no argument constructor that creates a default headphone.

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

 A method named changeVolume(value) that changes the volume of the headphone to the value passed into the method

Please help.

  • Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.

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

  • A private boolean data field named pluggedIn that specifies if the headphone is plugged in. The default value is false.

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

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

  • A private String data field named headPhoneModel that specifies the Model of the headphones.

  • getter and setter methods for all data fields.

  • A no argument constructor that creates a default headphone.

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

  • A method named changeVolume(value) that changes the volume of the headphone to the value passed into the method

Source Link

Java class named HeadPhone to represent a headphone set

Create a Java class named HeadPhone to represent a headphone set. The class contains:

 Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.

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

 A private boolean data field named pluggedIn that specifies if the headphone is plugged in. The default value is false.

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

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

 A private String data field named headPhoneModel that specifies the Model of the headphones.

 getter and setter methods for all data fields.

 A no argument constructor that creates a default headphone.

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

 A method named changeVolume(value) that changes the volume of the headphone to the value passed into the method

Create a TestHeadPhone class that constructs at least 3 HeadPhone objects. For each of the objects constructed, demonstrate the use of each of the methods.

Here is what I have thus far....

import java.awt.Color;
public class HeadPhones {
 public static final int LOW = 1;
 public static final int MEDIUM = 2;
 public static final int HIGH = 3;
 private int volume;
 private boolean pluggedIn;
 private String manufacturer;
 private Color headPhoneColor;
 public HeadPhones() {
 volume = MEDIUM;
 pluggedIn = false;
 manufacturer = "";
 headPhoneColor = Color.BLACK;
 }
 /**
 *
 * @return volume of headphone
 */
 public int getVolume() {
 return volume;
 }
 /**
 * set volume of headphone
 *
 * @param volume
 */
 public void setVolume(int volume) {
 this.volume = volume;
 }
 /**
 *
 * @return true if the headphone is plugged in, false otherwise
 */
 public boolean getPluggedIn() {
 return pluggedIn;
 }
 /**
 * set plugged in
 *
 * @param pluggedIn
 */
 public void setPluggedIn(boolean pluggedIn) {
 this.pluggedIn = pluggedIn;
 }
 /**
 *
 * @return manufacturer
 */
 public String getManufacturer() {
 return manufacturer;
 }
 /**
 * set manufacturer
 *
 * @param manufacturer
 */
 public void setManufacturer(String manufacturer) {
 this.manufacturer = manufacturer;
 }
 /**
 *
 * @return headphone color
 */
 public Color getHeadPhoneColor() {
 return headPhoneColor;
 }
 public String getColorName() {
 String colorName = "Black";
 if (headPhoneColor == Color.BLACK || headPhoneColor == Color.black) {
 colorName = "Black";
 } else if (headPhoneColor == Color.WHITE || headPhoneColor == Color.white) {
 colorName = "White";
 } else if (headPhoneColor == Color.RED || headPhoneColor == Color.red) {
 colorName = "Red";
 } else if (headPhoneColor == Color.PINK || headPhoneColor == Color.pink) {
 colorName = "Pink";
 } else if (headPhoneColor == Color.CYAN || headPhoneColor == Color.cyan) {
 colorName = "Cyan";
 } else if (headPhoneColor == Color.BLUE || headPhoneColor == Color.blue) {
 colorName = "Blue";
 } else if (headPhoneColor == Color.GREEN || headPhoneColor == Color.green) {
 colorName = "Green";
 } else if (headPhoneColor == Color.GRAY || headPhoneColor == Color.gray) {
 colorName = "Gray";
 }
 return colorName;
 }
 /**
 * set headphone color
 *
 * @param headPhoneColor
 */
 public void setHeadPhoneColor(Color headPhoneColor) {
 this.headPhoneColor = headPhoneColor;
 }
 /**
 * returns a string describing the current field values of the headphone
 */
 public String toString() {
 StringBuilder s = new StringBuilder("(");
 s.append("manufacturer = ").append(manufacturer).append(", ");
 s.append("volumne = ").append(volume).append(", ");
 s.append("plugged in = ").append(pluggedIn).append(", ");
 s.append("color = ").append(getColorName()).append(")");
 return s.toString();
 }
}

And this is my test class....

import java.awt.Color;
public class TestHeadPhones {
 public static void main(String[] args) {
 HeadPhones[] headphones = new HeadPhones[3];
 headphones[0] = new HeadPhones();
 headphones[0].setHeadPhoneColor(Color.CYAN);
 headphones[0].setManufacturer("Thinksound");
 headphones[1] = new HeadPhones();
 headphones[1].setManufacturer("Monster");
 headphones[1].setHeadPhoneColor(Color.white);
 headphones[1].setPluggedIn(true);
 headphones[1].setVolume(HeadPhones.HIGH);
 headphones[2] = new HeadPhones();
 headphones[2].setManufacturer("Sennheiser");
 headphones[2].setHeadPhoneColor(Color.ORANGE);
 headphones[2].setPluggedIn(true);
 headphones[2].setVolume(HeadPhones.LOW);
 for (int i = 0; i < 3; i++) {
 System.out.println("Headphone #" + (i + 1));
 System.out.println("toString() results: " + headphones[i]);
 System.out.println("getVolume() results: " + headphones[i].getVolume());
 System.out.println("getPluggedIn() results: " + headphones[i].getPluggedIn());
 System.out.println("getManufacturer() results: " + headphones[i].getManufacturer());
 System.out.println("getHeadPhoneColor() results: " + headphones[i].getColorName() + "\n");
 }
 }
}

Please help.

lang-java

AltStyle によって変換されたページ (->オリジナル) /