public void display(){}void是什么意思javaa中

java程序中成员变量与方法之间的点号是什么意思?例如语句t.display();_百度知道
java程序中成员变量与方法之间的点号是什么意思?例如语句t.display();
我有更好的答案
“.”+成员方法:理解成“执行”或“去”“.”+成员变量:理解成“的”StudentA.professor.haveClass()=&学生A的指导教授去上课&基本上这种解释可用
采纳率:49%
为您推荐:
其他类似问题
成员变量的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。Java Arrays: get() set() display() need help - Software Development | DaniWeb
Hi I'm in my first Java class, towards the end and am struggling with some code dealing with arrays.
I'm not looking for the answers but am spinning my wheels (as usual) and am stuck on a particular problem.
I'll list the problem here and then explain where I am in the process.
Any help will be greatly appreciated!
"Create a class named TVShow.java. Data Fields can
include a String containing the Name of the show,
a String containing the day that the show is
broadcast(i.e. “Monday”)and an integer for the channel
where the show can be viewed.
Methods will include a
constructor that requires values for all of the data
fields, plus methods to get, set and display the values
of the data fields. Create a UseTVShow.java file that
prompts the user to input up to 5 TV shows and
stores the data in an array of objects first, then
displays them as a list."
I am having a hard time figuring out how to link the two classes together with Arrays, more specifically the display() method within the TVShow class.
Then in the UseTVShow class I need help using the get(), set(), and display() methods because there is something I am just not understanding.
Take a look at the code and see if you can find my mistakes or what my code is lacking.
Thanks! import java.util.*;
import javax.swing.*;
public class TVShow
private String showN
private String showD
private int showC
//get methods
public String getShowName()
return showN
public String getDay()
return showD
public int getChannel()
return showC
//set methods
public void setShowName(String nameOfShow)
showName = nameOfS
public void setDay(String dayOfWeek)
showDay = dayOfW
public void setChannel(int myChannel)
showChannel = myC
//display's the show name, day, and channel.
public void display(String name, String day, int channel)
showName =
showChannel =
System.out.println(showName + " airs on " + showDay + ", on channel " +
showChannel + ".");
} import java.util.*;
import javax.swing.*;
public class UseTVShow
public static void main(String[] args)
//instantiate a new array with 5 elements.
//TVShow[] show = new TVShow[5];
String[] show = new String[5];
int highestSub = show.length - 1;
int x = 0;
String showString = "";
show[x] = JOptionPane.showInputDialog(null,
"Enter a list of up to 5 TV shows, or xxx to quit:");
while(!show[x].equals("xxx") && x & highestSub)
showString = showString + show[x] + "\n";
if(x & highestSub)
show[x] = JOptionPane.showInputDialog(null,
"Enter a list of up to 5 TV shows, or xxx to quit:");
for (x = 0; x & show. ++x)
System.out.println(show[x].display());
3Contributors 8Replies 22Views 7 YearsDiscussion Span
Last Post by Akill10
1. You have not created a constructor.
2. Why do you have a display method with the parameters your assignment spec said should be inside the constructor?
3. Your spec says you need to create an array of objects, which in this case will be TVshow objects, not an array of Strings
4. If you do not know how to create instances of your class, then you are moving too quickly. And should study up on object programming.
5. If you do know, then you will need a loop, asking for input, create an object using that info in it's constructor, and add each object to an array.
Edited 7 Years Ago
by Akill10: n/a
1. You have not created a constructor.
2. Why do you have a display method with the parameters your assignment spec said should be inside the constructor?
3. Your spec says you need to create an array of objects, which in this case will be TVshow objects, not an array of Strings
4. If you do not know how to create instances of your class, then you are moving too quickly. And should study up on object programming.
5. If you do know, then you will need a loop, asking for input, create an object using that info in it's constructor, and add each object to an array. 1. ok, I have added this above the first get method //contructor that requires values for all of the data fields
public showListing(String name, String day, int channel)
showName =
showChannel =
} 2. Good point, I moved those to the constructor called showListing, now the display method is just this: public void display()
System.out.println(showName + " airs on " + showDay +
", on channel " + showChannel + ".");
} 3. What do you mean TVShow objects instead of an array of Strings? The problem I'm doing is in the Arrays chapter.
this is my first lesson in Arrays so they are still pretty new to me.
Creating the TVShow objects is one of my biggest confusions right now.
I'm thinking I know.
I just took two weeks off of my online class (started a new job) and its hard to come back and remember everything.
5. Is this what you had in mind?
I am struggling with this as it is a little more intricate than I'm used to. for (x = 0; x & show. ++x)
show[x] = JOptionPane.showInputDialog(null,
"Enter a list of up to 5 TV shows, or xxx to quit:");
while(!show[x].equals("xxx") && x & highestSub)
showString = showString + show[x] + "\n";
if(x & highestSub)
show[x] = JOptionPane.showInputDialog(null,
"Enter a list of up to 5 TV shows, or xxx to quit:");
Edited 7 Years Ago
by curbster: n/a
Good point, I moved those to the constructor called showListing, 1. You cannot call a constructor by any name. It has to have the same name as the class. What do you mean TVShow objects instead of an array of Strings? 2. Create an array just like you do so for primitive types. object[] mytvshow = new object[5]; 3. Once you create these objects ,get the input from user into local variables and pass them as params to your constructor.
If you see that I am not understanding something, would you mind giving an example I could follow?
public class a{
//print this is my constructor.
} 1. Your constructor has to be TVShow(String name, String day, int channel).
2. To create an array of objects for class a that i've shown , the following syntax has to be followed a[] myvariableofa = new a[5]; Create it in the same way for your TVShow class.
Edited 7 Years Ago
by adarshcu: n/a
Thank you for the examples!
I follow those a lot easier.
For some reason I'm having a hard time with the terms.
I can read the code just fine but when it comes to creating it from a bunch of terms in the directions I struggle.
Anyway, following your recommendations I have changed the code as:
in the UseTVShow class: ...
public class UseTVShow
public static void main(String[] args)
//instantiate a new array with 5 elements.
TVShow[] show = new TVShow[5];
... In the TVShow class: public class TVShow
private String showName = "";
private String showDay = "";
private int showChannel = 0;
//contructor that requires values for all of the data fields
public void TVShow(String name, String day, int channel)
showName =
showChannel =
} so this is a start.
Now I have to figure out how to load the array with 2 strings and an int.
With just one object I'm not seeing how to do this.
If I created 3 arrays or one multi-dimensional array I would understand but how do you load an array with multiple strings and ints from one object?
What you have done above is correct. As regards to your doubts that you will have to create a multidimensional array to store 2 strings and an int , you are wrong. Now that you have got an array of objects. for(all elements in object array)
//get variable values from user.
//create a new TVShow object , pass the variables to the constructor.
show[i] = TVShow object created above.
} Hope you get the point here. You load an object into the array of abjects , and not individual data. That is the whole point of an object and a class.
Edited 7 Years Ago
by adarshcu: n/a
Thank you for the examples!
I follow those a lot easier.
For some reason I'm having a hard time with the terms.
I can read the code just fine but when it comes to creating it from a bunch of terms in the directions I struggle.
Anyway, following your recommendations I have changed the code as:
in the UseTVShow class: ...
public class UseTVShow
public static void main(String[] args)
//instantiate a new array with 5 elements.
TVShow[] show = new TVShow[5];
... In the TVShow class: public class TVShow
private String showName = "";
private String showDay = "";
private int showChannel = 0;
//contructor that requires values for all of the data fields
public void TVShow(String name, String day, int channel)
showName =
showChannel =
} so this is a start.
Now I have to figure out how to load the array with 2 strings and an int.
With just one object I'm not seeing how to do this.
If I created 3 arrays or one multi-dimensional array I would understand but how do you load an array with multiple strings and ints from one object?
My original post was assuming you understood those different terms, apologies.
This topic has been dead for over six months.
Have something to contribute to this discussion?
Please be thoughtful, detailed and courteous, and
be sure to adhere to our .
Post your Reply Alt+S
- 3 replies
- 15 replies
- 7 replies
- 33 replies
- 3 replies
- 6 replies
- 2 replies
- 14 replies
- 3 replies
- 2 replies
- 37 replies
- 4 replies
- 4 replies
- 7 replies
- 10 replies
So I have a JTextfield in the cells of 1 of the columns in my JTable I want to allow only numbers and up to one dot/period. Doesant ...
vb.Net - Regular Expression Tester Every now and then I find another use for a regular expression. For those not familiar with regular expressions, they can be as cryptic to ...
I'm trying to build a client and a server in the same program. For example, user 1 sends a packet of data to user 2, user 2 after receiving the ...Java练习题_方法和类
一道练习题,根据在主方法里的调用来创建一个MultiDisplay类实现以下方法:以下是我写的代码,不知道display这个方法怎么写QAQ
浏览 611回答 1
public class MultiDisplay {
private String displayM
private int displayC
public String getDisplayMessage() {
return displayM
public int getDisplayCount() {
return displayC
public void setDisplayMessage(String displayMessage) {
this.displayMessage = displayM
public void setDisplayCount(int displayCount) {
this.displayCount = displayC
public void display(){
for (int i = 0; i & displayC i++) {
System.out.println(displayMessage);
public void display(String displayMessage, int displayCount){
this.displayMessage = displayM
this.displayCount = displayC
display();
public static void main(String[] args) {
MultiDisplay md = new MultiDisplay();
md.setDisplayMessage(&Hello World!&);
md.setDisplayCount(3);
md.display();
md.display(&GoodBye cruel world!&, 2);
System.out.println(&Current Message: & + md.getDisplayMessage());
}我来解释下思路楼主,你看到 getXXX() 和 setXXX() 第一反应就是
这个XXX是这个类的属性,所以这个类肯定有 displayMessage 和displayCount 两个属性并且set是设置值的方法,然后, 因为 setDisplayMessage 接收String参数, setDisplayCount接收数字参数,所以 这两个属性分别是 String 和int 类型,而且displayMessage 是输出的内容, displayCount 就是输出的次数。能想到这后边就简单了, display就是直接输出了,而后边的system.out输出了&GoodBye cruel world!&, 正好是display重载方法接收的参数,可以判断这个重载方法是把接收的两个参数设为属性的值上边的代码里没有用到 getDisplayCount()
这个你可以删掉,不过为了便于维护建议还是留下
随时随地看视频35927 条评论分享收藏感谢收起public void foo(){
//do something...
println("haha"); // &&&=== 在这儿设置breakpoint 1
public void bar(){
println("hahaha"); // &&&=== 在这儿设置 breakpoint 2
当程序运行到breakponit1时,user stack 里会有三个frame || main 函数的 frame-------------------|| bar 函数的 frame-------------------&&&=== %ebp|| foo 函数的 frame------------------- &&&===%esp其中 esp 和 ebp 都是寄存器。 esp 指向stack 的顶(因为stack 向下生长,esp会向下走); ebp 指向当前frame的边界。当程序继续执行到brekapoing 2的时候stack 大概是这样的:|-------------------&&&=== %ebp|| main 函数的 frame------------------- &&&===%esp也就是说当一个函数执行结束后,它对应的call frame就被销毁了。(其实就是esp 和 ebp分别以东,但是内存地址中的数据只有在下一次写的时候才被覆盖。)说了这么多,终于该说什么东西放在stack 上什么东西放在heap 上了。最直白的解释:public void foo(){
int i = 0; // &= i 的值存在stack上,foo()的call frame 里。
Object obj = new Object(); // object 对象本身存在heap 里, foo()的call frame 里存该对象的地址。
===========图片引自CMU15-213的课件赞同 389 条评论分享收藏感谢收起扫一扫体验手机阅读
display分页程序流程
<span type="1" blog_id="740070" userid='
42篇文章,10W+人气,0粉丝
<span type="1" blog_id="740070" userid='

我要回帖

更多关于 java中void什么意思 的文章

 

随机推荐