The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Hello,
I have the gist of the computer program..but I am getting errors..need help with the class model and the import color.
Â
Â
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
private
private
private
private int volume;
boolean pluggedIn;
String manufacturer;
String headPhoneModel;
Color headPhoneColor; public HeadPhones() {
volume = MEDIUM;
pluggedIn = false;
manufacturer =( "");
headPhoneModel= ("");
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 model
*/
public String getheadPhoneModel() {
return model;
}
/**
* set head phone model
*
* @param model
*/
public void setheadPhoneModel(String model) {
this.model = model;
}
/**
*
* @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("model = ").append(model).append(", ");
s.append("volumne = ").append(volume).append(", ");
s.append("plugged in = ").append(pluggedIn).append(", ");
s.append("color = ").append(getColorName()).append(")");
return s.toString();
}
}
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.Ice);
headphones[0].setManufacturer("Proud");
headphones[0].setModel("Bold");
headphones[1] = new HeadPhones();
headphones[1].setManufacturer("RedBull");
headphones[1].setModel("123.br");
headphones[1].setHeadPhoneColor(Color.Blue);
headphones[1].setPluggedIn(true);
headphones[1].setVolume(HeadPhones.HIGH);
headphones[2] = new HeadPhones();
headphones[2].setManufacturer("Dell");
headphones[2].setModel("Bezerker");
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.prinltln("getModel() results: " +
headphones[i].getModel());
System.out.println("getHeadPhoneColor() results: " +
headphones[i].getColorName() + "\n");
}
}
}