Sorting Lists In Employee Class

Feb 5, 2014

A Employee Class where i want to sort there lists one by there salary and one by there name individually as per the requirement ? How we do it?

View Replies


ADVERTISEMENT

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

Sorting Linked Lists Via Consecutive Nodes

Feb 13, 2014

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)

[Code] .....

View Replies View Related

Merging And Sorting Array Lists Code Is Returning 0s?

Apr 19, 2015

I'm working on an assignment that asks for the user to input 2 lists of numbers and my program will merge and sort the lists using arrays and 2 methods. I think I have most of it down, but I'm not sure how to go about getting the user inputs. In my current code, it's giving me a bunch of 0s instead of a sorted list.

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

[code]....

View Replies View Related

Use Applet To Create Two Instances Of Employee Class

Jan 9, 2014

What I have to do: Use Applet to create two instances of the Employee class. Display the data on the Graphics object. Display in the applet the names and values of all of the instance variables in each instance of the class. Also display the value of any static variables.

What I'm doing:

import java.applet.Applet;
import java.awt.*;
public class EmployeeApplet extends Applet {
public static int topSalary = 195000;
int hoursPerWeek;
public static void setTopSalary (int s) {
if (s > topSalary)

[Code]...

I'm not able to display hours per week for e1 and e2.

View Replies View Related

Array Lists In A Class

Dec 6, 2014

What is going on here in the main class is a zoo that requires information to be read from and saved to a .txt file. I have made three arrayLists for each .txt file, I am getting errors for illegal start to an expression

import java.io.*;
import java.util.*;
public class ColumbusZoo
{
public static void addHelper(ArrayList<DomesticAnimal> a){
Scanner s = new Scanner(System.in);
System.out.println("What species");

[code].....

View Replies View Related

Rename To Functions And Lists Class File?

May 29, 2014

What are they the rename To functions and lists the class file?

View Replies View Related

Name Given To Two Or More Methods In Class With Same Name But Different Parameter / Argument Lists?

May 9, 2014

What is the name given to two (2) or more methods in a class with the same name but different parameter/ argument lists?

View Replies View Related

Class Defined Under Another Class - Sorting Elements In Reverse Order

Jul 4, 2014

I have never seen a class defined under another class ....

class pe{
static class pqsort implements Comparator<integer>
public into compare(Integer one,Integer two)
return two-one;
}
}

First I want to know how class pqsort is defined under class pe ....

And how the comparator used in this example is sorting elements in reverse order

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Sorting ArrayList Of A Class According To A Field

Oct 13, 2014

we have an Arraylist<Tweet>, and this class is defined as followe: public class Tweet implements Comparable<Tweet>, Serializable. now if we implement the method comparteTo, then will it be sorted automatically? I want to sort this array by any insert.

View Replies View Related

Sorting Dates - Saving Result In Class

May 18, 2014

So, I have two classes (bubble sort and insert sort) which are sorting dates. I need to save their comparings and reallocation of elements.

And I don't know how to do it. The point is if I want save that dates(comparings and reallocation) to Result class i need to create new instances of class in each sorting classes so i can't later do something with that, because I have null in Main class.

To avoid that problem i have tried to make Result class as singleton.. I mean: "public static final Results INSTANCE = new Results();" and then in classes "static Results result = Results.INSTANCE" without constructor and to save for example comparings i had method:

Java Code:

int SetComparings(){
return comparings++;
} mh_sh_highlight_all('java');

But it do not work too, because it overwrites old dates. Is there anyway to do not create instance of class? I don't want to copy whole code because it is too long and cant be unreadable, but i will put you structure of my program:

Java Code:

class BubbleSort{}
class InsertSort{}
class Results{}
class Sorting{} // class with switch to choose which way of sorting use
public class Main{} mh_sh_highlight_all('java');

View Replies View Related

Sorting Arrays In Descending Order With Collections Class

Jun 28, 2014

I am trying to create a java program to sort an array in ascending and descending order. Here is the program I created :

import java.util.Arrays;
import java.util.Collections;
public class ArraySort
{
public static void main(String [] args) {
int [] num = {5,9,1,65,7,8,9};
Arrays.sort(num);

[Code]...

BUT I GET THE FOLLOWING EROOR ON COMPILATION

ArraySort.java:12: error: no suitable method found for reverseOrder(int[])
Arrays.sort(num,Collections.reverseOrder(num));
^
method Collections.<T#1>reverseOrder(Comparator<T#1>) is not applicable

[Code] .....

What's wrong with my program?

View Replies View Related

Sorting Array Of Objects Based On One Of Class String Variables

Apr 8, 2014

I have a school assignment that involves me sorting an array of objects based on one of the class String variables. I am using as the title says a simple selection sort method. The problem I'm having is that when I run the program in debug mode, it never seems to enter the if statement in the inner loop. I would like to say I've tried a number of things to figure it out, but honestly I'm just stumped as to why it's not working.

Here is the code:

public static void sortTransactions(Transaction[] oTransaction){// This is the sorting method, obviously it's not done so it currently just prints to screen.
System.out.println("Successful call to sortTransaction()");
String min = "";
int curInd = 0;
Transaction[] temp = new Transaction[1];

[Code] ....

The output when I check to see if the array is sorted verifies that the array never does get sorted.

View Replies View Related

Unable To Call / Test All Of The 5 Sorting Methods At Same Time In Main Class

Dec 19, 2014

For reference I am programming Java in BlueJ. I am fairly new to the language and I am having trouble with sorting.

I am trying to call / test all of the 5 sorting methods (at the same time) in the main class. To be specific, the sorted list has to technically outputted 5 times.

I figured out how to call / test Quicksort:

Sorting.quickSort(friends, 0, friends.length-1);

But the others are not working correctly. Specifically these:

Sorting.mergeSort(friends, 0, friends.length-1);
Sorting.PbubbleSort(friends, 0, friends.length-1);
Sorting.PinsertionSort(friends, 0, friends.length-1);
Sorting.selectionSort(friends, 0, friends.length-1);

For reference, this is the output when it is not sorted:

Smith, John 610-555-7384
Barnes, Sarah215-555-3827
Riley, Mark 733-555-2969
Getz, Laura 663-555-3984
Smith, Larry464-555-3489
Phelps, Frank322-555-2284
Grant, Marsha243-555-2837

This is the output when it is sorted:

Barnes, Sarah215-555-3827
Getz, Laura 663-555-3984
Grant, Marsha243-555-2837
Phelps, Frank322-555-2284
Riley, Mark 733-555-2969
Smith, John 610-555-7384
Smith, Larry464-555-3489

This is the class Sorting, which I should note is all correct:

public class Sorting{
/**
* Swaps to elements in an array. Used by various sorting algorithms.
*
* @param data the array in which the elements are swapped
* @param index1 the index of the first element to be swapped
* @param index2 the index of the second element to be swapped
*/
private static <T extends Comparable<? super T>> void swap(T[] data,
int index1, int index2){
T temp = data[index1];
data[index1] = data[index2];

[Code]...

This is the Main class in which I am supposed to call the sorting methods, SortPhoneList:

public class SortPhoneList{
/**
* Creates an array of Contact objects, sorts them, then prints
* them.
*/
public static void main (String[] args){
Contact[] friends = new Contact[7];
friends[0] = new Contact ("John", "Smith", "610-555-7384");
friends[1] = new Contact ("Sarah", "Barnes", "215-555-3827");

[Code]...

View Replies View Related

How To Increase Hours Of Employee At Given Index

Oct 7, 2014

Basically I need to increase the hours of an employee at the given index. Index is the position of the employee in the array, and amount is how many hours you will be increasing by.

This is what I have so far,

public void increaseHours(int index, double amount){
for(Employee e: employees){
if(e instanceof HourlyEmployee){
HourlyEmployee he = (HourlyEmployee)e
he.increaseHours(amount);
}
}
}
}

I'm not sure how to use the index to do this correctly, all it's doing right now is adding hours to every hourly employee

View Replies View Related

How To Increase Hours Of Employee At Given Index

Oct 7, 2014

Basically I need to increase the hours of an employee at the given index.Index is the position of the employee in the array, and amount is how many hours you will be increasing by.

This is what I have so far,

public void increaseHours(int index, double amount){
for(Employee e: employees){
if(e instanceof HourlyEmployee){
HourlyEmployee he = (HourlyEmployee)e
he.increaseHours(amount);
}
}
}
}

View Replies View Related

Add New Employee And Enter A String / Data Does Not Appear In File

Mar 23, 2015

I'm just trying to append new employee information to a previously created file. When I type yes to add new employee and enter a string, the data does not appear in the file.

Java Code:

public class Records {
public static void main(String [] args) throws IOException {
Scanner input = new Scanner(System.in);
FileWriter fw = new FileWriter("dbs3.java", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);

[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

Building Calendar With Automated Employee Vacation Planner?

Apr 4, 2014

Every year, she has to plan when her employee's can go on vacation for the summer holidays - MANUALLY. It takes weeks to solve the puzzle, because she has several kinds of employee's hired, with different skills. And at all days there must be X amount of employees with skill1 at work, plus Y amount of employees with skill2 etc, and they also need special "off-days" in comparison to when they last worked and so on. It's quite the math puzzle.

I've worked a little with C#, and built a prototype of a Support System (Ticket based), so I got the basics down of programming, and I know Java and C# are quite alike, so I don't think making the switch will bother me that much.

The program should be easy to use for her, so it needs a visual calender that can be interacted with, and it should also be easy to see which employee is at work at that date and so on.

Will it be hard for me to build this kind of Calender, that allows the interaction I want?

Any open-sourced projects, or libraries that will make my task easier?

I plan on using NetBeans IDE for this project.

View Replies View Related

Report Employee Time Clock Cannot Find Corresponding Dates In And Out

Mar 8, 2014

I have this assignment to build an employee time clock. By using a menu you can enter an employee, enter punch in and out, and report.When I created the punch screen I wrote the in and out records to a file. Because there can be several employees punching in or out the file wrote each occurrence on different lines. Now I am attempting to write the report which you enter an employee Id and loop through the file to find the in and out date and then calculate the time (hours worked). I loaded the file into an Arraylist but now I cannot figure out how to loop through find the In and Out date - calculate the hours worked and then move on to the next day. here is the format of the file - employee id, place holder I or O, date, time, day. and sample

111221111i3/2/145:10 PMSunday
111221111o3/2/145:10 PMSunday
111331111i3/2/145:25 PMSunday
111331111o3/3/1412:47 PMMonday
111221111i3/3/1412:48 PMMonday
111221111o3/3/142:23 PMMonday
111441111i3/4/141:30 PMTuesday

[code]....

here is my code from the main screen.

public static void displayPunches()
throws FileNotFoundException, IOException, ParseException {
boolean isValid = false;
String choice = "y";
String emp = Validator.getLine(sc, "Enter I -Individual or A -All ");
if (emp.equalsIgnoreCase("A"))

[code]....

View Replies View Related

Adding A Phone Object Into Student / Employee Objects

Jun 1, 2014

I have to read in a file that that has Student, Employee, Faculty....such as name, last name, salary...etc

Example of a file input
Java Code: Student, John, Doe, [email]johnDoe[At]yahoo.com[/email], 123,Wonderland Ave, 21323,TX
PhoneNumber,Cell,111,222,3333
Student, Jesus,Satan,[email]jesus[At]satan.com[/email,666, HeavenHell Dr., 666666,CA
PhoneNumber,Work,111,333,5555 mh_sh_highlight_all('java'); Java Code: while(input.hasNext()){

[code]...

There is more code, but it's repetitive. Now, I keep getting an error. Array of bounds. I believe i get the error because the phone number. The phone number is on the next line..I created a different arraylist for phonenumber, but I dont know how to match it with the correct person, student, employee...etc.

View Replies View Related

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

How To Read Employee Thumb Impression From Biometric Instrument Using Java

Mar 13, 2014

How to read the thumb impressions by using bio-metric instrument using a java code and comparing the thumb impressions in java.

View Replies View Related

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 View Related

Recursion And Lists?

Aug 6, 2014

public void myFunc(MyNode n, ArrayList<MyNode> path) {
boolean hasChildren = false;
path.add(n);
int index = path.indexOf(n);
ArrayList<MyNode> statefulPath = new ArrayList<MyNode>();

[Code] ....

I have similar code that I stepped through in a debugger. After running the code I found that it built the desired tree, in this case a root node H with left child L and right child P. I want list of lists to contain all paths from root to leaf. I expected [H, L] and [H, P]. I discovered that statefulPath is not stateful; after a recursive stack frame pops, statefulPath still contains n! But that stack frame just popped! I expected to see statefulPath be [H] in the debugger and it was [H, L]! So I later have a list [H,L,P] which I don't want. How do I make the statefulPath list I want for my algorithm?

View Replies View Related







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