• Post Reply Bookmark Topic Watch Topic
  • New Topic

java programming project involving get and set methods?  RSS feed

 
Greenhorn
Posts: 16
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Modify the following class so that the two instance variables are private, there is a constructor that accepts both the player's name and sport and there are get and a set methods for each instance variable:

public class Player {
String name;
String sport;
}


2. You can pass an instance of this class to the JLabel constructor if you want to display text in the label.Select one:
a. myLabel
b. myText
c. String
d. JTextField
e. JLabelText

I wanted someone to give me an idea on how to start making this work?
cause i am not familiar with the terms here and
want to complete this program and I am new to java programming?
 
Ricardo Arteaga
Greenhorn
Posts: 16
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created my get and set methods and trying to figure how to pull my get and set variables into my constructor in my other class named : player class?
let me know if this makes sense, trying to make it good.

 
Marshal
Posts: 5656
767
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some remarks on your class implementation:

  • By convention, class names should always start with an uppercase letter, as in Player, or Variable.
  • There is no need to call super class's constructor with super() from your constructor - it will be added to the byte code by the compiler.
  • Make sure your method names follow its naming convention - the first word of a method should be in all lowercase letters, and the first letter of each of the rest of the words should be in upper case, as in setName(-)
  • It is better if parameter names are meaningful and follow conventions. Instead of having something like setName(String setname), you can just have something like this:

  •  
    Ricardo Arteaga
    Greenhorn
    Posts: 16
    C++ Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    okay fixed it


    my other class should take in my set and get method:
    which is call player class and i am trying to figure out how to
    pass an instance of test class to player class to display text in
    a jlabel, or jtextfield.

     
    Rancher
    Posts: 3742
    16
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Reread the question
    Ricardo Arteaga wrote:1. Modify the following class

    public class Player {
    String name;
    String sport;
    }

    The getter and setter methods should be in the Player class, not the Variable class. Same with the constructor that takes two arguments.
     
    Ricardo Arteaga
    Greenhorn
    Posts: 16
    C++ Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks it helps now its only one class.

    How do i pass an instance of this
    class to the JLabel constructor if
    you want to display text in the label?

    or i can Select one of these:
    a. myLabel
    b. myText
    c. String
    d. JTextField
    e. JLabelText

     
    Joanne Neal
    Rancher
    Posts: 3742
    16
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ricardo Arteaga wrote:How do i pass an instance of this
    class to the JLabel constructor if
    you want to display text in the label?

    You can't.

    Ricardo Arteaga wrote:
    or i can Select one of these:
    a. myLabel
    b. myText
    c. String
    d. JTextField
    e. JLabelText

    The Javadoc for JLabel (<- click on this link) shows you what constructors are available - so you will have to choose which one is suitable for the data you have.
    myLabel and myText appear to be variable names, so it would depend on what type they are as to whether they are useful.
     
    Ricardo Arteaga
    Greenhorn
    Posts: 16
    C++ Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    it was a typo thanks for all the help guys. really appreciate and want to try to get better at java aswell.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!