I am making a program of a bowling tracker. I made four names and then I have to add specific dates they played and then the score they got on those days. Then print to screen the names, the number of games they played, average score, last games score and last game date. I need help with the Linked list I want to make. I could do the rest, i just need an example of how to use the LinkedList.

import java.lang.String;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

public class BowlingGame {
   
    public static void main(String[] args) 
    {
        String [] bowlingNames = {"Steve", "James", "Allen", "Tyson"}; 
        ArrayList al = new ArrayList();
        al.addAll(Arrays.asList(bowlingNames));
        for (Iterator iter = al.iterator(); iter.hasNext(); ) 
        {
            String names =  (String)iter.next();
            System.out.println(names);
        }
       String [] gameDates = {"7 January, 11 Feburary 27 Feburary 9 March", "13 January, 1 Feburary, 3 March, 19 March", "1 January, 16 Feburary, 5 March, 18 March", "31 January, 23 Feburary 28 Feburary 10 March"};
       LinkedList list = new LinkedList();
       list.add(Lists.asList(gameDates));//Need help over here
       for (Iterator iter = list.iterator(); iter.hasNext(); ) 
        {
            String dates =  (String)iter.next();
            System.out.println(dates);
        }
    }
}

Recommended Answers

All 8 Replies

I need help with the Linked list

Can you explain how you want to use the LinkedList class?

Can you explain how you want to use the LinkedList class?

I want to use it so that the names are linked to the score (yet to be made) and the dates. This is the Question if it could explain anything.
Use the collections framework and generic types to create a bowling score tracker collection. Design a data structure that will be used as elements in a collection. Each element should contain a unique name of the bowler and a list of scores and dates of the games they have played.

Then print to the screen each:

Bowler name
Number of exams taken
Average score of all of the exams
Score of their last game
Date of their last game
Provide test cases to prove your collection works.

Can you explain what your problem is using a linked list?
What does the "//Need help over here" comment mean?
How do you want to use the linked list at that point in the program?

I want to link the dates to the names and then create another linkedlist that links the scores to the dates

list.add(Lists.asList(gameDates));//Need help over here

instead of this
Trying adding a Object

For example

list.add(playerDetails)

Here playerDetails is a object of a class PlayerDetails and this should contains

Class PlayerDetails 
{
  String PlayerName;
  int    score;
  Date   lastPlayedDate; .... etc
}

and create objects like this

PlayerDetails  p1 = new PlayerDetails();
p1.name = "Steve";
p1.score = "28";
..
list.add(p1);

PlayerDetails  p2 = new PlayerDetails();
p2.name = "James";
p2.score = "2";
..
list.add(p2);
...

Let me know ur views

I want to link the dates to the names

I don't think you understand what the word "Linked" in linked list means.
It refers to the connection between the elements in a list. They are linked together.
The elements in the list are objects of the same type.
Your usage of link seems to be the normal "linking" that a reference from one object to another object.

I need a little more help with my program. msvinaykumar, your post helped me but I want to add the data in an ArrayList. I also want to know a way that I can print the name and date they played.
My code

package bowlingtracker;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
 
public class BowlingTracker {   
    
    public static void main(String[] args) 
    {
        class bowlingTracker 
        {
            String PlayerNames;
            String score;
            String date;
        }
        ArrayList details = new ArrayList();
        bowlingTracker p1 = new bowlingTracker();
        p1.PlayerNames = "Steve"; 
        p1.score = "252";
        p1.date = "7 January 20011";
        System.out.println(p1);
        /*details.addAll(Arrays.asList(p1));
        for (Iterator iter = details.iterator(); iter.hasNext(); ) 
        {
            String playerDetails =  (String)iter.next();
            System.out.println(playerDetails);
        }*/
    }
}

a way that I can print the name and date they played.

A couple of ways.
Add some get methods to the class that you can call to get the name and date
Or add a override to the toString method and have it return a String with the data you want to print.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.