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 7 of 7

Thread: Assignment Help - Need to Figure Out How to Integrate the Classes

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Assignment Help - Need to Figure Out How to Integrate the Classes

    I'm given 2 classes. It's basically a game scoreboard and it runs through all the values to determine who the winner is. No user input is needed.
    Sample output at the end looks like this:

    Vancouver - 3 wins, 2 losses, 0 ties = 6 total points
        Calgary - 2 wins, 3 losses, 2 ties = 6 total points
        Edmonton - 1 wins, 3 losses, 2 ties = 4 total points
        Toronto - 2 wins, 3 losses, 2 ties = 6 total points
        Ottawa - 4 wins, 3 losses, 1 ties = 9 total points
        Montreal - 4 wins, 2 losses, 1 ties = 9 total points
     
        The season winner(s) with 9 points
        Ottawa
        Montreal

    The two classes are Game.class and Schedule.class

    Game.class
    public class Game
    {
     
        public Game(String s, String s1, int i, int j)
        {
            homeTeam = s;
            awayTeam = s1;
            homeScore = i;
            awayScore = j;
        }
     
        public String getHomeTeam()
        {
            return homeTeam;
        }
     
        public String getAwayTeam()
        {
            return awayTeam;
        }
     
        public int getHomeScore()
        {
            return homeScore;
        }
     
        public int getAwayScore()
        {
            return awayScore;
        }
     
        private String homeTeam;
        private String awayTeam;
        private int homeScore;
        private int awayScore;
    }

    Schedule.class
    public class Schedule
    {
     
        public Schedule()
        {
            games = new Game[20];
            games[0] = new Game(teams[0], teams[1], 5, 3);
            games[1] = new Game(teams[1], teams[2], 4, 4);
            games[2] = new Game(teams[2], teams[3], 3, 3);
            games[3] = new Game(teams[4], teams[3], 2, 4);
            games[4] = new Game(teams[4], teams[5], 6, 3);
            games[5] = new Game(teams[5], teams[1], 5, 4);
            games[6] = new Game(teams[0], teams[3], 4, 3);
            games[7] = new Game(teams[1], teams[4], 3, 4);
            games[8] = new Game(teams[2], teams[0], 2, 3);
            games[9] = new Game(teams[3], teams[1], 1, 4);
            games[10] = new Game(teams[4], teams[2], 5, 3);
            games[11] = new Game(teams[5], teams[3], 4, 4);
            games[12] = new Game(teams[1], teams[4], 3, 3);
            games[13] = new Game(teams[2], teams[5], 2, 4);
            games[14] = new Game(teams[3], teams[5], 1, 3);
            games[15] = new Game(teams[4], teams[0], 5, 4);
            games[16] = new Game(teams[5], teams[4], 4, 3);
            games[17] = new Game(teams[0], teams[3], 3, 4);
            games[18] = new Game(teams[5], teams[2], 2, 3);
            games[19] = new Game(teams[4], teams[1], 1, 4);
        }
     
        public String[] getTeams()
        {
            String as[] = {
                "Vancouver", "Calgary", "Edmonton", "Toronto", "Ottawa", "Montreal"
            };
            return as;
        }
     
        public Game getGame(int i)
        {
            return games[i];
        }
     
        public static final int GAMES = 20;
        private String teams[] = {
            "Vancouver", "Calgary", "Edmonton", "Toronto", "Ottawa", "Montreal"
        };
        private Game games[];
    }

    I admit that I really don't know where to start with this. I know I need to make a class that will invoke a main method to integrate the other 2 classes together. So it will output what I showed earlier to determine the winner, based on the score and games.
    They provide these classes and I need to work on them. I don't understand how games[] is passed through. Under the schedule.class, is it just a parameter that's done 19 times? Any help is greatly appreciated. I really don't understand how to start with this.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Assignment Help - Need to Figure Out How to Integrate the Classes

    how games[] is passed through
    The code provides getGame() to get an element in games[]
    The Game class has methods to get at the values it contains.
    The Schedule class's constructor creates and initializes the games array.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Assignment Help - Need to Figure Out How to Integrate the Classes


  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Assignment Help - Need to Figure Out How to Integrate the Classes

    Quote Originally Posted by Norm View Post
    Yeah I posted to another site. I wasn't sure how big the following of users was on devshed. But it seems this forum is more comprehensive and larger than the other.

    I appreciate you guys pointing me in the right direction. I'll check out the tutorial vids and work on the class that's gonna use the methods in game to use the array from schedule.
    I'll update if I need more tips. Thanks

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Assignment Help - Need to Figure Out How to Integrate the Classes

    In Schedule class, the getGame method returns the values in the games array.

    My issue is, how do I pass the getGame method through an object so it prints those values to output?

    getGame(int i) being the method, would I make an object like this?

    Game showGames = new Game();
    System.out.println(getGame());

    ?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Assignment Help - Need to Figure Out How to Integrate the Classes

    how do I pass the getGame method
    You don't pass a method. You pass a reference to the class containing the method. If you create a new instance of the Game class it won't have the data from the other instance.
    You can use the Arrays class's toString method to format an array for printing.

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Location
    Pob. Vieja Batuan, Bohol
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Assignment Help - Need to Figure Out How to Integrate the Classes

    The Method getGame(int i) is a method that gets the value of the array games[]. By calling getgame() in the main method, we can get the values inside the array.We can get the attributes inside the games[] array by using loop method, we can use i--.

Similar Threads

  1. assignment troubles polymorphism (guide for assignment included)
    By tdawg422 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 8th, 2011, 10:01 AM
  2. Integrate Java and C
    By rcbandit2 in forum Java Native Interface
    Replies: 3
    Last Post: August 30th, 2011, 12:13 PM
  3. [SOLVED] can't figure out..
    By darego in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 10th, 2010, 02:26 PM
  4. I'm new at this and can't figure it out
    By jaheh06 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 22nd, 2010, 08:44 AM
  5. Replies: 1
    Last Post: February 22nd, 2010, 08:20 AM