where the first number is student number and the second is their grade. I need to read this information from a .txt file and dynamically create a new node containing that student's number and mark, and insert it in the correct position in the linked list (in descending order based on grade). So I get that each Node needs to contain two data types, an Int for Student # and a Double for their grade, and I'm pretty sure I've done it correctly with my StudentNode class which can be found in the source code linked above.
But what I don't get it using that class to create Nodes in my main class and then sort them based on their Double grade value WHILE they are being sorted. I just don't understand where to actually put the methods and such that does these things. Apparently I'm supposed to have three classes.
One named StudentNode which is just the node info, which I have done.
The second is called StudentList which is apparently supposed to contain the head of LinkedList and the methods I need? I'm not sure how it ties into StudentNode though.
The third and final is just the main class which I'll use to test it.
Then after all that I need to print out the median mark through a recursive method that isn't allowed to use any loops or call and functions/methods that use loops. The function should return the node in the list which contains the median mark. Secondly, in order to find the median, you need to know how many items in total are in the list. Your recursive function must calculate that number (also recursively); you may not keep track of this count elsewhere your program. Your recursive solution should only examine each node only once, and the depth of the recursion should be equal to the number of nodes in the list.
Here's my current in-progress code.
import java.io.FileNotFoundException;
import java.util.Scanner;
class StudentNode {
private int studentNum;
private double grade;
private StudentNode next;
[Code] .....
I'm pretty sure the StudentNode class is fine, it's the StudentList class that I'm not sure about. I'm not sure how to add nodes since there isn't a getNext() method in the StudentList class.
I'm trying to read from a file. we made an array of LinkedList and when I'm reading from the file i get a runtime error "index out of bounce in line 66"
import java.lang.*; import java.util.*; public class HashTester{ LinkedList_t [] hash; LinkedList_t [][] doubleHasher; int size;
How can i convert this linked list code to a read from input.txt
The first line in the input file will give the elements to initialize the linked list with. Consecutive lines will provide operation instructions.
Your code should read one line at a time. After reading each line, it should perform the corresponding operation and print the linked-list on the console.
If an operation is not possible, it should print "N/A".
Sample input file. Please note, the comments (// ...) are given for explanation, the input file will not have them:
4, 5, 6, 3// First line. This will provide the initial values for the linked list : 4->5->6->3 1, 9// Add a 9 at the front of the linked-list. After this operation the linked-list should be: 9->4->5->6->3 2, 1// Add a 1 at the end of the linked-list. After this operation the linked-list should be: 9->4->5->6->3->1 3, // Delete the first node in the linked-list. After this operation the linked-list should be: 4->5->6->3->1 4, // Delete the last node in the linked-list. After this operation the linked-list should be: 4->5->6->3 5, 11// Delete the node with the value 11 in it. Since this is not possible, it should print "N/A" 5, 6// Delete the node with the value 6 in it. After this operation the linked-list should be: 4->5->3
Why do I make private Node<AnyType> next;And why do I have an inner class of Node for a linked list?I had the same topic in C, but there it was somehow easier than in java. Because there you have pointers.
Write a Java function Sum2List that takes two lists L1 and L2 of the same size and returns list L that contains the sum of data inside the corresponding nodes of lists L1 and L2.
ex: L1 = {1,2,3} L2 = {4,5,6} L = {5,7,9}
I do not know how to iterate through two different lists >>
I have used unmarshalling concept to retrieve the data elements... I have to check whether the elements satisfy few regulations when compared with data in Database. So, i thought of grouping the employees depending on EType. I have created a Map with linkedlist of employees. Say Map<String, LinkedList<Employe>>EmpMap=new Map<String, LinkedList<Employe>>();
I have already created a class named Employee which has all the setter and getter methods for employee.
Here am going to take Etype(Employee type) as key and linkedlist(list of employees of certain type) as value. How to iterate these linked lists and place them in my Map.
I have the following code that supposed to perfrom sorting on the linked list using method sort in order usind node concept of Linked List but seems to give inlogic results. the following code tests only the values lower than the first value but i can't manage to sort the data higher than the first entered value;
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
import java.util.*; public class ListNode<T extends Comparable> { ListNode<T> nextNode; T data; public ListNode(T item)
I'm working with Doubly Linked Lists and using Java Generics..
My nodes looks like this: class DNode<E> { DNode<E> previous; DNode<E> next; E element;
//and all methods inside }
My list of Nodes looks like this: class DLL<E>{ private DNode<E> head; private DNode<E> tail; private int size;
[code]....
As you can see, as arguments they get "E o"...I need to write a program, which from the main function asks the users how long is the list, and after they type it's length, I ask them to start typing the elements (integers)...and this is how my main method is written, but I can't seem to make it work, specialy when I call the "insLast" method,I guess it's because the arguments i'm giving to the function...how to read the elements and write them into the list?
public static void main(String[] args) throws IOException { DLL<Integer> lista=new DLL<Integer>(); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String s = stdin.readLine(); int N = Integer.parseInt(s); s = stdin.readLine(); String[] pomniza = s.split(" "); for (int i = 0; i < N; i++) { lista.instLast(Integer.parseInt(pomniza[i])); }
I am creating a chained hash table that uses my own LinkedListclass to handle collisons. Here is where my issue is occuring: I start with an array of LinkedLists, my "hash table", intially set to null. When i wish to add a word, if the desired location is null, I create a new LinkedList, place it in that array index. I then create a new LinkedListNode and set the head of the new LinkedList to the new node.
My issue is occuring here: Whenever I set the head of my new LinkedList to my new LinkedListNode all of my previously created linkedlists also have their head changed to the new node.
My debugger shows that I am truly creating new linkedlists every time. I was afraid each array index was just pointing to a single array, but that is evidently not the issue. Below is all the relevant code
public class SetOfStrings { private int arraySize; private LinkedList[] mainArray; private int totalCount; //other methods here public boolean add(String toAdd) { int hashToAdd = hash(toAdd);
[code]....
SUMMARY: Whenever I set the head of a Linked List to a new node, it changes the head of all my linked lists to point to the same new node
I'm not sure if my understanding of PriorityQueues is correct, so I'm trying to check if my reasoning is valid. I'm supposed to compare the Big-O for arrays and linked lists for the following instructions:
Insert 100 objects having the priorities 1, 2, 3, ... , 99, 100 Big-O for Array: __________ Big-O for Linked List: ___________
Insert 100 objects having the priorities 100, 99, 98, ... , 2, 1 Big-O for Array: __________ Big-O for Linked List(Assume no tail reference): ___________
If my understanding is correct, priority queues take in items randomly with no particular order, but they are removed according to the priority of each element. If what I've said is true, wouldn't that mean that inserting any number of objects would be O(1) for both linked lists and arrays? If the PriorityQueue has no particular order, then wouldnt each add() simply insert something to the next array index/linked list node?
I am trying to implement product method below which returns the set representing the Cartesian product of the current set and a given set (the Cartesian product contains all ordered pairs (a, b) where a belongs to the current set, and b belongs to the given set). The product should be a ListSet <Tuple<E>> object where each ordered pair is a Tuple element. (I have a Tuple class which implements an ordered tuple)
What am I trying to do in the product method : Make 2 for loop and inside the for loop make an array of <E> then set the 2 elements of the tuple then again set tuple and add it to arrayList. how to set 2 elements of the tuple and set tuple ??
public class ListSet<E> implements Iterable<E>{ SinglyLinkedList<E> sl; public ListSet(){ sl = new SinglyLinkedList<E>();
Write a java program to store employee information in a linked list, the program should implement the following functions:
The program should display the list of functions, and ask the user to enter the number of function that he/she wants to do, then perform the function as it is required in the previous table.
import java.util.*; public class Employee { Scanner in = new Scanner(System.in); String Name; String Address; String Department; int ID; int Salary;
[code]....
this is my out put
Please choose a number: 1-Add a new employee 2-Update employee's info 3-Remove employee's info 4-Exit 1 Enter name: Enter address: 2 Enter department: 3 Enter ID: 4 Enter salary:
now:
1- why are not my adding coming out in the output only the Enter name & Enter address ??
2- how can I add names and ID's and information to test that program
How to go through each link item in both lists, and directly link them into the new list in order without using insert()
class Link { public long dData; // data item public Link next; // next link in list // ------------------------------------------------------------- public Link(long dd) // constructor { dData = dd; } // ------------------------------------------------------------- public void displayLink() // display this link { System.out.print(dData + " "); } } // end class Link
For example, if I had a text file with one line such as "first, second, third", would there be a way to make it so I could make "first" go to the first array list, "second" to the second, and "third" to the third?
I haven't posted any of my code so far as it wouldn't be right to be handed the finished code on a platter and I should put the work into it, but I'd just need a loop to make it go through the rest of the lines in the text file to add all the first, second and third parts of each line, right?
(I already know how to input data from a file, but not how to split up a line into bits to put into different array lists).
The requirement asked me to write a Java program to read information from the file, display the original information along with the player's average score of the season (one line for each player), and announce who is the highest average-scoring player of the team. But I always only get the highest which show the last player.
I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...
The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data. Here is the base Product class that must be used to create the objects for the array.
public class Product { public String pName; public String stringName; public double price; public int quanity;
[Code]...
these continue for about 40-50 entries, they are not seperated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name seperated with spaces, then price after a comma, then quanity after the second comma.....
I am working on a project that requires me to build a database with random access file, representing products, the base product contains a name (about 30 characters), a price (double), and a quantity (integer). I have worked on this project for probably 15+ hours and have tried so many things and feel like I've barley made any progress...
The part i am really struggling with is taking the data from the text file and creating an object array with it using the product class. Once ive accomplished that, i have to use that data to create a random access file with the data.
Here is the base Product class that must be used to create the objects for the array.
public class Product { public String pName; public String stringName; public double price; public int quanity; //Constructor public Product( String pName, double price, int quanity )
[code]....
and then here is the data from the text file that i must extract to use to create product objects.
Dill Seed,938,34
Mustard Seed,100,64
Coriander Powder,924,18
Turmeric,836,80
Cinnamon (Ground Korintje),951,10
Cinnamon (Ground) Xtra Hi Oil (2x),614,31
Cinnamon (Ground) High Oil (1X),682,19
these continue for about 40-50 entries, they are not separated by a blank line though i had to add those so it would display correctly, each entry is on its own line with name separated with spaces, then price after a comma, then quanity after the second comma.....
I need to write a program that will let a user input name, age, email, and cell phone number, and commit the input to a text file. They need to add multiple entries. I figured out how to create the file and write to it, but when the user enters a second set of information, the first is overwritten. How can I make the file be added to instead of overwritten? The following is my code:
try { FileWriter writer = new FileWriter("ContactInformation.txt"); BufferedWriter bw = new BufferedWriter(writer); nameTextField.write(bw); bw.newLine();
The point of this program is to read characters from a txt file and store them into a 2D array. After this has been accomplished, the information is to be printed in the same manner it is read from in the txt file.
Here is the code I have so far:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException
[Code] ....
And this is the error I am receiving when trying to accomplish the goal of the project:
Exception in thread "main" java.lang.NumberFormatException: For input string: "############" at java.lang.NumberFormatException.forInputString(Unk nown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Maze.<init>(Maze.java:15) at Main.main(Main.java:20)
What's going on here and how I can correct this?? The information I am trying to store in a 2D array and then print is this:
The main method will drive your program by doing the following:
-Create an array to hold all the individual golfers and par scores (type is Golfer[ ]). -Prompt the user for a data file containing the Par scores and the player names and score. The format of the input file should look like
I am now stuck. I am writing a program that reads information from a data file and runs it through but program. However, I am almost finished with the program, but cannot figure out the last few parts.
public class Storm { private final double KnotsToMPH = 1.15; // global user-defined types: private int beginDate; private int duration; private String name;
[Code] .....
I have not attached the data file because it contains a total of 360 lines of hurricane information.