我按照以下说明骑着斗巴.我无法弄清楚如何使用toString()方法来打印我的数据值.我也不知道如何将颜色打印成字符串来表示"黑色"或"蓝色".我无法弄清楚如何使用布尔值来表示"已连接"或"已断开连接".
创建一个名为HeadPhone的Java类来表示耳机集.该课程包含:
•三个常量,分别为LOW,MEDIUM和HIGH,值为1,2和3,表示耳机音量.
•名为volume的私有int数据字段,用于指定耳机的音量.默认音量为MEDIUM.
•名为pluggedIn的私有布尔数据字段,用于指定是否插入耳机.默认值为false.
•名为manufacturer的私有字符串数据字段,用于指定耳机制造商的名称.
•名为headPhoneColor的私有颜色数据字段,用于指定耳机的颜色.
•所有数据字段的getter和setter方法.
•无参数构造函数,用于创建默认耳机.
•名为toString()的方法,返回描述耳机当前字段值的字符串.
•名为changeVolume(value)的方法,用于将耳机的音量更改为传递给方法的值
创建一个构造至少3个HeadPhone对象的TestHeadPhone类.
public class TestHeadPhone {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// construct an object
HeadPhone headPhone = new HeadPhone();
System.out.println("Manufacturer: " + headPhone.getManufacturer());
System.out.println("Color: " + headPhone.getColor());
System.out.println("Currently: " + headPhone.getStatus());
System.out.println("Volume: " + headPhone.getVolume());
if(headPhone.getStatus() == false){
System.out.println("Please plug the Head Phones into a device.");
}
headPhone.setNewHeadphone();
System.out.println("\n" + "Manufacturer: " +
headPhone.getManufacturer());
System.out.println("Color: " + headPhone.getColor());
System.out.println("Currently: …Run Code Online (Sandbox Code Playgroud)