The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
whats wrong with this code?
Posted by: Ali | February 8, 2010 @ 11:24am
Java Code
[
Download
]
import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { ArrayList list = new ArrayList(); Employee number1= new Employee("David",20); Employee number2= new Employee("Michael",10); Employee number3= new Employee("Bob",15); Employee number4= new Employee("Tom",12); Employee number5= new Employee("Carl",16); list.add(number1); list.add(number2); list.add(number3); list.add(number4); list.add(number5); Collections.sort(list); for (int i = 0; i < list.size(); i++) { Employee e = (Employee) list.get(i); System.out.println(e.toString()); } } } public class Employee { // Class constants static public final int MAX_DAYS = 5; static public final int MAX_REGULAR_HOURS = MAX_DAYS * 8; // Class variables static private int numEmployees = 0; // Instance variables private String name; private double payRate; // Constructor methods // Initialize a new employee's name to the empty string and her // pay rate and hours worked to 0 public Employee() { name = ""; payRate = 0; } // Initialize a new employee's attributes to the given parameters public Employee(String name, double payRate) { this.name = name; this.payRate = payRate; numEmployees++; } // Set an employee's name public void setName (String name) { this.name = name; } // Get an employee's name public String getName () { return name; } // Set an employee's pay rate public void setPayRate (double newRate) { payRate = newRate; } // Get an employee's pay rate public double getPayRate () { return payRate; } // Compute and return an employee's weekly pay public double computePay() { return payRate * MAX_REGULAR_HOURS; } static public int getNumEmployees() { return numEmployees; } // Return a string representation of a employee's name, pay rate // and hours worked. public String toString() { String str = "Name: " + name + "\n" + "Pay rate: " + payRate + "\n"; return str; } public int compareTo(Object o) { Employee employee= (Employee)o; if(this.getName().compareTo(employee.getName()) > 0) return 1; else if( this.getName().compareTo(employee.getName()) < 0) return -1; return 0; } }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.61 / 8
49 Votes
http://codebin.yi.org/491
page generated in 0.01 seconds