[英]Create a method to change the volume of the headphones, java class
This is only my second coding course, but I am loving everything about it.这只是我的第二个编程课程,但我喜欢它的一切。 However, I am having trouble with creating a final method before I can turn it in. The program runs perfectly fine as of now, but I need to create a method called changeVolume(value) that changes the volume of the headphone to the value passed into the method.
但是,在我将其打开之前,我无法创建最终方法。该程序目前运行得非常好,但我需要创建一个名为 changeVolume(value) 的方法,该方法将耳机的音量更改为传递的值进入方法。 I feel like I am overthinking it, but I cannot seem to create any portion of code to switch the "volume level" for the headphones.
我觉得我想多了,但我似乎无法创建任何代码部分来切换耳机的“音量”。 Any help would be appreciated, but I need to step away for a bit and rest my eyes so I thought I would reach out for some help before I do!
任何帮助将不胜感激,但我需要走开一会儿,让我的眼睛休息一下,所以我想我会在做之前寻求一些帮助!
The picture above is my program running上图是我运行的程序
The following code below is my class HeadPhone.java, and the main class (TestHeadPhone.java) is where everything will be called.下面的代码是我的类 HeadPhone.java,主类 (TestHeadPhone.java) 是所有将被调用的地方。 I left out getters/setters and a lot of other things so I hope this gives a good idea.
我遗漏了 getter/setter 和很多其他东西,所以我希望这能提供一个好主意。 If not, just let me know and I will share any portion of code you need!
如果没有,请告诉我,我将分享您需要的任何代码部分!
//Constants defined
int LOW = 1;
int MEDIUM = 2;
int HIGH = 3;
//Private data fields
private int volume;
private String manufacturer;
private String headPhoneModel;
private Color headPhoneColor;
private boolean pluggedIn = false;
//Default constructor for default headphones
public HeadPhone () {
volume = MEDIUM;
manufacturer = "Apple";
headPhoneModel = "Air Pods";
headPhoneColor = Color.WHITE;
pluggedIn = false;
}//End default constructor
//toString method
public String toString(){
return "\n------Your current headphones are------ " + "\n"
+"Volume Level: " + volume + "\n"
+"Headphone Manufacturer: " + manufacturer + "\n"
+"Model of Headphones: " + headPhoneModel + "\n"
+"Color of Headphones: " + headPhoneColor + "\n"
+"The headphones are plugged in: " + pluggedIn;
}//End toString
You should try to set the volume:您应该尝试设置音量:
volume = "The volume";
(And can you show more code to understand entierly how youtr program is working? so add the main mathod to your post so I can understand better wath you are tring to achive) (你能展示更多的代码来完全理解你的程序是如何工作的吗?所以在你的帖子中添加主要的数学,这样我就可以更好地理解你正在努力实现的目标)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.