Creates A Single Linked List That Stores Names And High Scores And Prints Them

Sep 29, 2014

a project I am working on. Its a program that creates a singly linked list that stores names and high scores and prints them. For some reason it is printing an entry extra times. Also my remove function is not working properly

GameEntry class:
package project;
public class GameEntry implements Comparable<GameEntry> {
private String name;
private int score;  
public GameEntry(String n, int s) {
name = n;

[Code]...

View Replies


ADVERTISEMENT

Program To Maintain A List Of High Scores Obtained In A Game

Dec 6, 2014

I am stuck on what to put in my functions for this question: Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:

-initialiseHighScores () which sets all high scores to zero.

-printHighScores() which prints the high scores in the format: "The high scores are 345, 300, 234", for all exisiting high scores in the list (remember that sometimes it won't be full).

-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.

-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list

here are my functions the insertScore is missing because I am having troubles with it.

public static void initialiseHighScores (int[] scores, int size)
{
for (int i = 0; i < size; i++)
{
scores [i] = 0;
}
}
public static boolean higherThan (int[] scores, int size, int newScore)
{

[Code]...

View Replies View Related

Quick Single Linked List

Feb 11, 2015

i'm currently going over single linked list, and i'm coming across an error which i do not know how to get by. I'm using single linked list for now just for study purposes, then i would move on to double.

Error: No enclosing instance of type LList is accessible. Must qualify the allocation with an enclosing instance of type LList (e.g. x.new A() where x is an instance of LList).

public class LList {
private static class Node<E>{
private E data;
private Node<E> next;

[code]....

View Replies View Related

Single Linked List Boolean

Feb 13, 2015

i'm currently studying over single linkedLists and i'm just writing various methods for it. One method i'm currently stuck on is writing a remove method where it returns a boolean true if its found and it will delete it, and false if the target isn't found. My problem is that it always comes up as flase and i know that the target is in the linked list. Here is the code for my method.

Java Code: public boolean remove(E item){
Node<E> ptr = head;
while(ptr!= null && !item.equals(item))
ptr = ptr.next;
if(ptr.data.equals(item)){
ptr.next = ptr.next.next;

[code]...

View Replies View Related

Error In Single Linked List

Sep 13, 2014

package progProject5;
// Implementation of single linked list.
public class SingleLinkedList<E> {
private Node<E> head = null;
private int size = 0;
// Methods

[Code] ......

I am in learning process and I know its very basic question but I got stucked at addAfter() where I need to insert the node after the given node.

View Replies View Related

Quicksort With Single Linked List / 1 Node Parameter

Nov 12, 2014

I have a custom linkedList(single) class that uses the provided node class. Now I have another class to QuickSort this.(left out for brevity, i just wanna focus on editing the L.head). However, instead of passing the quicksort method the entire linkedList, I want to pass it just the head from the linkedlist.

My problem is accessing this head node and changing it from the quckSort method/class, and I dont want to delete it or simply just change the element value

Main:

public class TestLinkedList {
public static <E extends Comparable<E>> void main(String[] args) {
MyLinkedList<Integer> L = new MyLinkedList<Integer>();
L.add(3);
L.add(1);
L.add(2);
System.out.println("Initial=" + L);
MySort.quickSort(L.head);
System.out.println("After ="+L);
}
}

QuickSort:

public class MySort {
public static <E extends Comparable<E>> void quickSort(MyNode<E> list) {
list = list.next;
}

Node Class:

public class MyNode<E extends Comparable<E>> {
E element;
MyNode<E> next;
public MyNode(E item) {
element = item;
next = null;

[code]....

View Replies View Related

Java Program To Implement A Single Linked List Structure

Jul 27, 2014

I'm trying to build a program that contains the ability to:

(1) insert new node at head,
(2) print out contents of the list in order,
(3) remove first node from head,
(4) remove last node from tail,
(5) find a target value,
(6) give total number of occurrences of a target value, and
(7) give total number of items in list.

The areas I'm struggling with implementing are: (

- remove from tail - I know how to find the final node but I can't quite figure out how to set it to null since its initial type is an integer.
- find a target value - how to make the parameters quite workout so the user can simply input an integer value.
- The solution is probably really simple but I can't figure out how to print out the results of these methods when I call them.

public class Node
{
private int data;
private Node link;
// Node Constructor 1
public Node()
{
data = 0;
link = null;

[code]....

View Replies View Related

Method That Print Data Of Single Linked List Backward Using Stack

Apr 23, 2015

I am trying out solving the question but i am stuck.The problem is to write a method that print data of single linked list backward using stack.The question is as follow

public class Stack{
public boolean isEmpty(){};
public void push(int n){};
public int peek(){};
public int pop(){};
}

public class node{
int data;
node next;
}

public class list{
node first;
}

View Replies View Related

Find High And Low Scores From File

Aug 28, 2014

I am trying to figure out how to report the high and low scores with names from a file. The format is like:

6352 J@me$$
663843 BOBBBB1
etc...

This is my code so far.

import java.io.*;
import java.util.*;
public class Assignment1
{
public static void main(String[] args)throws IOException

[code]....

View Replies View Related

How To Make XML - Game To Hold High Scores Of Three Different Levels

May 22, 2015

I am a beginning programmer and was learning how to make an XML. It was for a simple game and only needs to hold the highscores of three different levels. Here is what I coded:

try {
OutputStream fout= new FileOutputStream("highScores.xml");
OutputStream bout= new BufferedOutputStream(fout);
OutputStreamWriter out = new OutputStreamWriter(bout, "8859_1");

[code]....

My issue is that I run this code every time I create the program and the scores are reset to 0. How can I make a small change so that I only run this block of code and create the XML the first time the program is run?

View Replies View Related

High Scores On Table - Shifting Elements In Array To The Right

Dec 7, 2014

I'm trying to write a program that asks a user how many high scores they want on a table, then the users types the inital highscores and is repeatedly asked to place more high scores on the table, which if larger than any existing high score, will take its place and shift the other scores down.

Although for the shifting and inserting of that next score the code just doesnt seem to be working, the insertScore function is where im getting the main exception, and im not sure why?

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class HighScores {
public static void main(String[] args) {

[Code] .....

View Replies View Related

Validate Names And Test Scores - Logical Error

Oct 14, 2014

I am working in the field of validating data. I need to validate names and test scores and i keeping getting errors in my code. I keep tracing back all the errors and now I am stuck at a logic error. It is giving me a the validate sentence over and over even when i type stuff in. I have searched up how to do the .equals to a string but it doesn't give me a accurate enough to my problem.

import java.util.Scanner;
public class P5A
{
public static void main (String args[]) {
System.out.println( "Always Show" );
Scanner reader = new Scanner(System.in);

[Code] .....

View Replies View Related

Java Method Overloading Ask For Two Names And Prints Three Different Greetings

Feb 24, 2014

The class Overloading below asks for two names and prints three different greetings. Your task is to write the class methods missing from the class declaration. Methods print the greetings as shown in the example print.

Hint:The names and parameter types of the needed methods can be checked from the main method because all methods are called there. This exercise also does not require you to copy the source code below to the return field.

The method declarations will suffice.

Example output
Type in the first name: John
Type in the second name: Doe

**********
Hi!
**********
Hi, John
**********
Hi, John and Doe
**********

import java.util.Scanner;
public class Overloading {
public static void main(String[] args) {
String firstName, secondName;

[Code] ....

View Replies View Related

Prompts User To Enter 5 Test Scores And Their Names - Calculate And Display Average

Sep 24, 2014

Using Bluejay. Need code that prompts user to enter 5 test scores and their names. Calculate the average and display.

First initial and last name , 5 test scores, and average

View Replies View Related

How To Append New Entry In A List Of 100,000 Names Without Iterating List Each Time

Apr 22, 2015

I have a list of 100,000 + names and I need to append to that list another 100,000 names. Each name must be unique. Currently I iterate through the entire list to be sure the name does not exist. As you can imagine this is very slow. I am new to Java and I am maintaining a 15+ year old product. Is there a better way to check for an existing name?

View Replies View Related

List Diving Scores Using Arrays

Nov 16, 2014

Alright, so, for my CS project, we're supposed to list diving scores. However, there are four sections (which I've made in the code) and each section has 9 scores. Of those nice scores, the highest and lowest must be eliminated and then the total needs to be figured out. We're supposed to be using arrays for this...

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class Diving {
public static final int MAX_DIVES = 51;
public static void main (String[] args) {

[Code] .....

The text file link is uploaded on this post.File is here:

View Replies View Related

Sort Linked List Through The Nodes Of List - Data Of Calling Object

Feb 14, 2014

I have some class called sorted to sort the linked list through the nodes of the list. and other class to test this ability, i made object of the sort class called "list1" and insert the values to the linked list.

If i make other object called "list2" and want to merge those two lists by using method merge in sort class. And wrote code of

list1.merge(list2);

How can the merge method in sort class know the values of list1 that called it as this object is created in other class.

View Replies View Related

Creating A Score List And High Score List?

Jan 7, 2015

I am creating a program called "Mad Math Machine". This program is to generate random arithmetic questions, with integers ranging from -12 to 12, for the user to answer. The user has three lives. Once they get more than three questions wrong, they run out of lives, and their "score" (the number of questions they answered correctly) is taken.

I have the large chunk of the program (the arithmetic questions and answers) completed. The only part I am stuck on is the scoring system. I believe that arrays would be useful for this task, but I have little idea of where to start. Here is what the scoring list should be able to do:

- It should print out the top ten recent players and their scores.
- A separate list should show the top-two highest scores of all time.

*I didn't think it was relevant, but I can include the program code. Up until this point, I have created methods to keep track of the score, but I have simply left them commented out so I could build the rest of the program.*

View Replies View Related

Linked List Implementation Of List Interface?

Oct 5, 2013

So we have an assignment regarding a linked list implementation of a given list interface.

In my list interface, the method contains(T anEntry) is defined.

In the LList implementation, contains is already implemented as part of getting the core methods in.

Now I am being tasked with the following:

Provide a second implementation of the method contains2(T anEntry) that calls a private recursive method

Private boolean contains (T anEntry, Node startNode) that returns whether the list that starts at startNode contains the entry anEntry.

I've written the private recursive method already. That's not an issue (at least not right now).

But what I don't understand is how startNode is supposed to be populated when this private contains method is called from the public contains2 method? contains2 only takes one parameter: anEntry. the private method takes two parameters: anEntry and startNode. How am i supposed to provide startNode when I am calling contains2?

View Replies View Related

Randomizing Names From A List?

Feb 2, 2014

I'm trying to use the DataFactory class to pull in a list of names, as I need to populate my app in development with randomized test data for testing.

DataFactory

So, I can get a random name like so:-

package domainentities;
import java.util.Random;
import java.util.Collections;
import org.fluttercode.datafactory.AddressDataValues;

[Code] .....

But - it always prints 'Lindsey'. I need a way of completely randomizing but I can't see the class has a method to let me do this? I can use the randomize method but this takes an int argument which will always bring back the same index value (same name).

I wonder if I am over complicating this. I can use a simple String array of names, but I don't want, like 10,000 names in my array and I want a good way of generating good, randomized data. Perhaps a .csv file of names could be read in? Here is a second method I wrote but I don't have the skills to know how to read the array values from my large .csv file:

public String randomSecondName(){
String[] lastNames = {"Smith", "Jones", "Collins","Jackson",
"Dearsley", "Trump", "Carr", "O'Connell", "Dyer", "Furstzwangler" };
Random ran = new Random();
String lastName = lastNames[ran.nextInt(lastNames.length)];
return lastName;
}

View Replies View Related

How To Make A List Of Names With Java

Oct 16, 2014

One of my assignments was to make a program that would read a sequence of names and then list them all.Just to be clear, it would read them all first, and then it would list them all at the same time.

View Replies View Related

Searching Through Array (List Of Names)

Oct 5, 2014

An array which contain a list of names. I let for a user input and I use that to search through the array. For example lets say the string name "Christian" is stored inside the names array and the user types in Chri, the program looks in the array and finds a name that contains Chri and prints them out. How do I go about doing this?

View Replies View Related

Write Java Program That Asks User For List Of Names?

May 21, 2015

I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.

My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.

Here is the code so far.

/*
* File: UniqueNames.java
*/
import acm.program.*;
import java.util.*;

[Code].....

View Replies View Related

List Interface Class That Has Operations For Linked List And LList Class

Oct 6, 2014

I have this ListInterface class that has operations for my linked list and a LList class. The Llist and ListInterface classes are perfect. My job is to create a driver, or a demo class that showcases these operations. That being said, heres the driver so far:

import java.util.*;
public abstract class DriverWilson implements ListInterface
{
public static void main(String[] args)
{

LList a = new LList();

[code]....

View Replies View Related

Convert A List Of Related Object To Single Line

Jul 17, 2014

I am using Java 1.6, I have this class ....
 
import java.util.ArrayList;
import java.util.List;
public class TestDrive
{
  public TestDrive()
  {
  super();

[Code] ....
 
What is the most efficient way to group the preferences of the same type, In other word I want just a print statement to print this line.
 
BREAKFAST(Eggs,Milk),SPORTS(Basket,Tennis),....

View Replies View Related

Inserting A Set Into Linked List?

Mar 21, 2014

What I'm supposed to do is make a method to insert a set of Tiles to the list,i.e.,a detour(make sure that the inserted detouris compatible with thecurrent path so that the resultingpathdoesnot have any gaps). But I'm confused on how to go about doing it. I was thinking of maybe just adding 1 to the current Node.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Scanner;
public class Path {
static Tile startTile;

[code].....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved