Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Newbie problem

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Newbie problem

    Here's the problem:
    Problem A: Lane Basketball team. Objectives: Creating classes, passing parameters to objects from a driver program.
    Write a class for the Lane Basketball team named Athlete which has the following attributes: name, position, height in feet and inches. Write appropriate mutator (set) methods which change each of the attribute values, and accessor (get) methods which return the attribute values. Create a driver program which creates four athlete objects, stores the following values in each, and then displays the values for each athlete.
    Height
    Name Position Feet Inches
    A. Samuels Guard 6 3
    C. Truman Forward 5 11
    S. Hendricks Point Guard 6 1
    N. Anderson Center 6 5

    ... I've written the Athlete class but I'm not entirely sure how it's supposed compile together.

    /**
    * Athlete Class
    */

    public class Athlete
    {
    // Fields
    private String PlayerName; //player name
    private String PlayerPosition; //player position
    private double PlayerHeight; //height of player


    public Athlete(String name, String pos, double hgt)
    {
    PlayerName = name;
    PlayerPosition = pos;
    PlayerHeight = hgt;
    }

    public void setPlayerName(String name)
    {
    PlayerName = name;
    }

    public void setPlayerPosition(String pos)
    {
    PlayerPosition = pos;
    }

    public void setPlayerHeight(double hgt)
    {
    PlayerHeight = hgt;
    }

    public String getPlayerName()
    {
    return PlayerName;
    }

    public String getPlayerPosition()
    {
    return PlayerPosition;
    }

    public double getPlayerHeight()
    {
    return PlayerHeight;
    }
    }

    Then I have to create a driver program. This is where it gets sticky. Am I supposed to input the attributes into the driver program? How do I go about doing this? So far I'm up to here.

    public class AthleteTest
    {
    public static void main(String[] args)
    {
    String testName;
    String testPosition;
    double testHeight;

    Athlete display1 = new Athlete(A. Samuels, Guard, 6.3);
    Athlete display2 = new Athlete(C. Truman, Forward, 5.11);
    Athlete display3 = new Athlete(S. Hendricks, Point Guard, 6.1);
    Athlete display4 = new Athlete(N. Anderson, Center, 6.5);

    I have a feeling I'm like TOTALLY off.

    Thanks in advance for your help.


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Newbie problem

    Print each of the attribute for each athlete to System.out. I'd use a different method, like
    public void printAthlete(Athlete athlete)
    {
      String name = athlete.getPlayerName();
      String position = athlete.getPlayerPosition();
      double height = athlete.getPlayerHeight();
      //Use System.out to print these.. not sure how you want it to look.
    }

  3. The Following User Says Thank You to Tjstretch For This Useful Post:

    kingsnans (October 23rd, 2011)

  4. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Newbie problem

    So the athlete class looks okay for this assignment? Thanks

Similar Threads

  1. Newbie problem
    By Vigge645 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 27th, 2011, 05:15 AM
  2. Output problem (newbie)
    By Asido in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 8th, 2010, 12:19 PM
  3. newbie GUI/ event handling problem
    By zyspt in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 10th, 2010, 11:36 AM
  4. Newbie Programming problem
    By Pingu in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 01:10 AM
  5. Re: Java Newbie Code Problem
    By erinbasim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 01:05 AM