Write A Java Program To Store Employee Information In A Linked List

May 12, 2015

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

View Replies


ADVERTISEMENT

Program That Displays Information For Employee Objects Of Different Types

Apr 29, 2014

I'm making a program that displays information for "employee" objects of different types. This works with a hierarchy that goes Person→ Employee→ Fulltime/Adjunct, and a driver that tests the inheritance. The Person class is given and only supplies the name, the employee class manages the year hired and the ID, and the types of employee classes manage the salaries.

One object (called staff[2]) is supposed to first be printed with default information and then later updated via set methods. I figured out how to update the name, but I don't know how to update the rest of the information because the employee's name is managed in the Person class and the reset of the information is managed in the less-general classes, and the objects are all in an array of Person.

How do I call the set methods necessary to update more of staff[2]?Output (scroll to see the updating section)

The current year is 2012

Name: Flintstone, Fred
ID Num: BR-1
Year Hired: 2005
Years Of Service: 7
Salary: 65000.12
Fulltime Type Employee

[code]....

View Replies View Related

Polynomial Linked List - Store Coefficients

Apr 27, 2015

Write java codes for the following LinkedList base program:

The program should have following three classes:

Node.java , Polynomial.java, Project1.java

A one-variable polynomial of degree n is an arithmetic expression of the form:

a0+a1 x+a2 x^2+..........+an x^n

where a0 a1,a2, ......, an are the coefficients. Design and implement a class named Polynomial that uses a singly-linked list to store the coefficients (so there is virtually no limit on n ). Include a method that adds two polynomials and another method that multiplies two polynomials. For example, the following two polynomials

2 + x^2 - 3x^3 and 1 - x - 2x^2 + 3x^3

are represented by 2, 0, 1, -3 and 1, -1, -2, 3, respectively. The sum of these two polynomials is

3 - x - x^2

which is represented by 3, -1, -1; and the product of the two polynomials is

2 - 2x - 3x^2 + 2x^3 + x^4 + 9x^5 - 9x^6

which is represented by 2, -2, -3, 2, 1, 9, -9.

Note that you must write your code to maintain and manipulate the linked list data structure (i. e., do not use a utility library such as java.util.LinkedList). Email one week before the due date to get a data file to test your program. The data file will contain several pairs of polynomials. Each polynomial is given on a separate line (with coefficients separated by space instead of comma), and there is an empty line between two pairs. Your Java program should read and echo each pair of polynomials, compute and report their sum and product, and go on to process the next pair until the end of input. Specifically, the main method must look like:

while (not end of input) {
read and echo a pair of polynomials P1 and P2;

output sum (P1, P2); // Static method returning a polynomial
output product (P1, P2) // Static method returning a polynomial
}

Hand in a program listing with clear internal documentation and a printout of the results of execution using the test data file. Also email all JAVA program files (Node.java - the same as the one given in class except for the element field that becomes int type for this project, Polynoial.java, Project1.java) so your work can be easily recompiled and tested.

Data file will be like: coefficients of polynomials, not exact, just for as an example of

(The data file will contain several pairs of polynomials)

2 3 0 1 -3

1 -1 -2 3, 9

Output will be in same format with sum and product: coefficients of polynomials, not real, just for as an example.

5 -6 0 7 4

4 -2 -3 3, 7

sum: ...

product:...

...........

View Replies View Related

Program That Is To Store DVD Information?

Nov 11, 2014

i have a program that is to store DVD information and when i enter all the information asked it returns no info. I have a DVD inventory file and a DVD extended file.

DVDinventoryprogram class
package inventory2;
import java.util.Scanner;

[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

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

Program Should Read File Contents And Store Information In Array Of Golfers

Dec 3, 2014

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

Par, 3, 4, 4, 3, 4, 3, 5, 3, 4
George, 3, 3, 4, 3, 4, 2, 3, 3, 4
Paul, 4, 5, 4, 3, 6, 3, 4, 3, 5
Ringo, 3, 3, 4, 3, 4, 2, 4, 3, 4
John, 4, 4, 4, 3, 4, 2, 5, 3, 4

Your program should read the file contents and store the information in your array of Golfers.

View Replies View Related

Singly-linked List Program Challenges

Oct 22, 2014

read a text file that has some polynomials in a specific format and perform an arithmetic expression. This needs to be done using a singly-linked list to store the coefficients of the polynomials. There needs to be two methods, one that adds the two polynomials and one to multiply them. So for example suppose i had the following set of polynomials in the text file:

2+x2-3x3 and 1-x-2x2+3x3

these are represented by 2, 0, 1, -3 and 1, -1, -2, 3 respectively. The of the two polynomials is: 3-x-x2 which is represented as: 3, -1, -1

The product of the two polynomials is: 2-2x-3x2+2x3+x4+9x5-9x6

My code is just echoing the data in the text file and not actually doing any arithmetic.

import java.io.*;
import java.util.Scanner;
class Node {
public int digi1;
public int digi2;
public Node nxt;

[code]....

View Replies View Related

Basic Console Java Program - Generate Employee ID

Feb 27, 2014

Basic console java program. I need to generate an employee id. I have an employee class that I will paste here so you can see my fields and constructors.

public class Employee {
private String firstName;
private String lastName;
private int id;
public int nextUniqueId = 0;
public Scanner sc = new Scanner(System.in);

[Code] ....

View Replies View Related

Create Program Which Inherit Stack And Queue From A Linked List Class

Nov 18, 2014

I want to create java program in which i want to inherit stack and queue from a linked list class and also make infix to postfix inherit from stack and periority queue from queue class.Ho can i make this program.

View Replies View Related

Write A String Name Variable To Store Letters / Dotes And Spaces Only In Java?

Apr 5, 2014

I am trying to write a program and the name variable can only store letters,dotes and spaces. But whenever I enter a space, the program doesn't work. Following is my code.

import java.util.Scanner;
import java.util.*;
public class Space {
public static void main(String []args) {
Scanner reader = new Scanner(System.in);

[Code] ....

View Replies View Related

Write A Java Application To Display Layout Of Information In Typical Business Card Order

Jun 25, 2014

ABC is a company that designs and prints personal business cards. The company has asked you to write a Java application to display the layout of the information in a typical business card order. Data items in a typical business card include the customer's name, address, city, state, postcode, home phone number, and work phone number.

Write, compile, and test a Java class that displays these data items in a command window. Alternatively, you could also create it using a dialog box. Please include appropriate comments in your class.

Please named your class BusinessCard(LIM).java. (eq. BusinessCardLIM.java)

View Replies View Related

Java Linked List Reverse

Apr 12, 2014

I am creating a recursive method to reverse a linked list in java. It works the first time when I call it, but I want it to work where I call it a second time and it reverses it to the original state. How can I get that to work with this implementation?

public void reverseList() {
System.out.printf("%-16s%-3s%n", "Name", "Score");
System.out.println("--------------- -----");
reverseList(first);
} public void reverseList(Node aNode) {
if (aNode != null) {
reverseList(aNode.next);
System.out.printf("%-15s%6s%n" , aNode.name , aNode.score);
}
}

View Replies View Related

Josephus Circular Linked List Java

Apr 6, 2014

I am creating a josephus java program with a circular linked list.This is what the methods are suppose to do

a. size(): Returns the number of items in the list.

b. isEmpty(): Returns true if the list is empty and false otherwise

c. advance(): Moves the cursor from the current position to the next item. If the cursor is at the end (tail) of this list, calling advance() should make the cursor refer to the first element in the list. If the list is empty, this operation should have no effect.

d. getCurrent(): Return the String value in the node referenced by the cursor unless the CircularLL is empty in which case write an error message to System.err.

e. add(String data): Adds a new item to the list by creating a newNode and linking it to the end of the circular linked list. The last node should point to the new node and then you should make lastNodeInserted point to new node as well.) Please note that a circular linked list is always circular. The last node should point to the beginning node. When there is only one node in a CircularLL, its next should point to itself. This method updates currNode when the first node is added, and always updates lastNodeInserted and numNodes. Take care when adding the first node this is a special case and should be handled differently.

f. remove(): If the list is empty, write an error message to System.err indicating that an attempt was made to remove from an empty queue and return null. Assuming the list is't empty, this method removes the node currently referenced by the cursor, reassigns the cursor to point to the next node in the list, and returns the String value stored in that node. To keep the list linked, you'll need to locate the previous node to the one youre removing and connect its next to the node which follows the one youre removing. Create a local Node variable (prev) to find it. Consider and handle the special case when there is only one node and youre removing it. And make sure to update lastNodeInserted whenever you remove the node that it is pointing to.

g. toString(): This should return a String representation of the circular linked list, with the first value displayed being the data of the first node added (not the data in the last node).

public class CircularLL {
private class Node {
String data;
Node next;

public Node(String data) {
this.data = data;
this.next = null;

[code].....

View Replies View Related

Merge Sort Java And Linked List?

Dec 11, 2014

I've playing around with linked lists and methods for sorting. So far I've tested the iterative sort, insertion sort, quick sort and they all worked perfectly. Now, I am trying to implement merge sort that would take a linked list of jobs and sort them according to their priority. I found a few solutions on the web, of which I am trying to implemented this one: LeetCode.

My system is a simple one, I do have a linked list of print jobs, each of which has the priority. The following code should sort my print queue and return the link node of the first sorted element. Here's the code.

//defining a job that has priority
public class Job {
private int priority;

[Code]....

The problem I've been trying to solve is that I am getting the stack overflow at line

ListNode<T> h1 = mergeSort(left);

meaning that I am getting into a loop somewhere down through the process of breaking the linked list into half, half or halfs and so on.

View Replies View Related

Write A Program That Reverses A List Of 15 Integers Preferably In Place

Nov 24, 2014

Write a program that reverses a list of 15 integers preferably in place.

View Replies View Related

Best Way To Store Information?

Jul 7, 2014

I'm doing desktop application about recipes. User can create new recipe, add information. I want to sort recipes, save them somewhere, maybe make it possible to send recipes over network to other users. But I don't know where and how store information about those recipes. I always used to use .txt files for storing needed information, but it seems that it is not the best option.

View Replies View Related

Reverse Double Linked List In Java - Descending Order

Sep 12, 2014

I have the following double linked list and I'm supposed to order it descending (reverse) using the printInReverse() method; since the list orders itself ascending when the numbers are added, how could I order it descending in this method? Here's the code without implementing descending/reversing methods:

package test;
import java.util.Scanner;
public class MyList {
private Scanner userInput;
private Integer selectedOption;
private MyListElement firstElement = null;
private boolean exitRequested = false;

[Code] ....

I tried to declare a previousElement variable but I didn't figure out how I'd do that.

View Replies View Related

Read ASCII Art Map And Store Information In 2D Array

Feb 12, 2014

I've written some code to do this, but it's not working as I expect. This is what the ASCII map looks like:

###################
#.................#
#......G........E.#
#.................#
#..E..............#
#..........G......#
#.................#
#.................#
###################

Here's how I've tried to store the information in a 2D array:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
 public class Map {
 public void importMap() throws IOException{
BufferedReader br = new BufferedReader(new FileReader("map.txt"));
String line;

[Code] ....

But it's not printing out what I'm expecting. It's printing out:

[[#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [

What is printed is much larger than what I've copy and pasted but I can't post it all here.

The error I get is:

Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at Map.importMap(Map.java:26)
at Map.main(Map.java:44)

View Replies View Related

Create Class Employee Which Contains A String Variable Employee Number

Jul 13, 2014

I have searched for totalPay is always 0 and the responses are not related to my problem (that I can tell).This is a class assignment and I have other questions besides why the method is not working.

Here are the instructions: Create class Employee which contains a String variable Employee Number, a String variable Employee Name, an integer Hours Worked, and a double Pay Rate. Create get and set methods for each variable. Provide method "totalPay" which calculates and returns the total pay by multiplying the hours worked by pay rate. Use figure 8.12 as an example of an object with get and set methods.

Unlike other examples of this type question online this one has Employee Number as a String variable. The book is How to Program Early Objects by Deitel 9th edition.We have instructions to do only what she has told us too. At this point it is objects and getter and setter methods. It is only the beginning of week 2.

ON THE LINES WHERE I HAVE QUESTIONS I AM COMMENTING IN ALL CAPS. NOT SHOUTING, JUST TRYING TO MAKE IT EASIER

package test11;
import java.util.Scanner;
public class Test11 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]..

Essentially I cannot figure out how to get the method getTotalPay to be called by the Scanner and do the math. I also have this random bracket problem that showed up about an hour ago.

The concept I don't get is that if I omit this.employeeNumber =id; etc. I error all over the place. If I change it to this.employeeeNumber = employee Number Netbeans tells me it is assigning itself to itself, which I know. When I try to use id instead of employeeNumber I get errors all over. If i remove "this" from it the same happens. why in public class employee I have to change to those values (id, name, etc) in the construct and set them again? I don't see where or how they can be used, so why do i have to do it?

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

Linked Lists - Reading Information From A File

Oct 29, 2014

Basically, the program is to be able to read information from a file like this;

11111 63.5
22222 59.9
33333 82.4
44444 73.1
55555 77.3
66666 99.5
77777 68.7
88888 53.2
99999 66.8

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.

View Replies View Related

Read Characters From Txt File / Store Them Into 2D Array And Print Information

Oct 10, 2014

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:

############
#.#........#
#.#.######.#
#.#....#...#
#.###.*#.#.#
#...####.#.#
#.#.#..#.#.#
#.#.#.##.#.#
#o#......#.#

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

Hurricane Java Project - Read Information From Data File And Run It Through But Program

Dec 2, 2014

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.

View Replies View Related

Unable To Write Text File With Information Stored

Jul 27, 2014

I am trying to write to a text file with information stored like this.

brick 500
stone 500

And so on. Here is the code I am using to write to the file.

switch(record){
case "brick":
x.format("%s%n", "brick " + value);
closeFile();
break;
case "log":
x.format("
%s%n", "log " + value);
closeFile();
break;

When I write like this, putting deletes the first line. What I can look into or other functions that would be useful?

View Replies View Related







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