How do I generate objects randomly in java? - java

I have an abstract class called "Student" and 2 subclasses "Graduate" and "Undergraduate", they both have the same parameters.
I want to create 10 Student objects randomly, some from the "Graduate" and some from the "Undergraduate" classes.
I want to print the displayStudent() method for all objects created, I got stuck on how to randomly generate the 10 students so they are all random of type graduates and undergraduates.
public abstract class Student {
private int ID;
private double GPA;
public Student(int ID, double GPA) {
this.ID = ID;
this.GPA = GPA;
}
public int getID() {
return ID;
}
public double getGPA() {
return GPA;
}
public abstract String getLevel();
public abstract String getStatus();
public final String displayStudent() {
return getLevel() + " ID>> " + getID() + ", GPA>> " + getGPA() + ", Status>> " + getStatus();
}
}
public class Graduate extends Student{
public Graduate(int ID, double GPA) {
super(ID, GPA);
}
#Override
public String getLevel() {
return "graduate";
}
#Override
public String getStatus() {
if( getGPA() >= 3) {
return "honor";
} else if (getGPA() >= 2 && getGPA() <= 3) {
return "good";
} else {
return "probation";
}
}
}
public class Undergraduate extends Student {
public Undergraduate(int ID, double GPA) {
super(ID, GPA);
}
#Override
public String getLevel() {
return "undergraduate";
}
#Override
public String getStatus() {
if( getGPA() >= 3) {
return "honor";
} else if (getGPA() >= 2 && getGPA() <= 3) {
return "good";
} else if( getGPA() > 0 && getGPA() < 2) {
return "probation";
} else {
//for any number that is not in the range of the GPA
return "invalid GPA!";
}
}
}

Try this.
using the ternary operator ?: is key.
exp ? a : b says if exp is true, do a, else do b
I used the loop index+1 as the id.
If the boolean is true, graduate, otherwise undergrad.
The double is multiplied by 4 to get the GPA.
Random r = new Random();
List<Student> students = new ArrayList<>();
for (int i = 0; i < 10; i++) {
students.add(r.nextBoolean() ?
new Graduate(i+1, r.nextDouble() * 4) :
new Undergraduate(i+1, r.nextDouble() * 4));
}
Note, If you change the displayStudent() method to toString() like so
#Override
public String toString() {
return getLevel() + " ID>> " + getID() + ", GPA>> "
+ getGPA() + ", Status>> " + getStatus();
}
You can just print the object directly without having to call any method.
You will probably need to format the GPA to eliminate unnecessary precision. Check out String.format.

Related

How do I create an boolean equals method compares objects in an array

My programming assignment tasked me with writing an increase/decreasePay abstract method that must be put in my abstract employee class. I can't seem to get the the method correct in HourlyWorker so that it will take increase or decrease the pay by a "percentage". My math is sound (monthly pay - or + (monthly pay * the percentage), but my output in my test class is coming out the same after increasing/decreasing pay. Any help?
Employee class:
abstract public class Employee
{
private String lastName;
private String firstName;
private String ID;
public abstract void increasePay(double percentage);
public abstract void decreasePay(double percentage);
public abstract double getMonthlyPay();
public Employee(String last, String first, String ID)
{
lastName = last;
firstName = first;
this.ID = ID;
}
public void setLast(String last)
{
lastName = last;
}
public void setFirst(String first)
{
firstName = first;
}
public void setIdNumber(String ID)
{
this.ID = ID;
}
public String getLastName()
{
return lastName;
}
public String getFirstName()
{
return firstName;
}
public String getName()
{
return firstName + lastName;
}
public String getIdNumber()
{
return ID;
}
}
HourlyWorkerClass
public class HourlyWorker extends Employee
{
private int hours;
private double hourlyRate;
private double monthlyPay;
public HourlyWorker(String last, String first, String ID, double rate)
{
super(last, first, ID);
hourlyRate = rate;
}
public void setHours(int hours)
{
this.hours = hours;
}
public int getHours()
{
return hours;
}
public void setHourlyRate(double rate)
{
if ( hours > 160 )
this.hourlyRate = hourlyRate * 1.5;
else
this.hourlyRate = rate;
}
public double getHourlyRate()
{
return hourlyRate;
}
public void setMonthlyPay(double monthlyPay)
{
monthlyPay = hourlyRate * hours;
}
public double getMonthlyPay()
{
return hourlyRate * hours;
}
public void increasePay(double percentage)
{
monthlyPay = monthlyPay* percentage;
}
public void decreasePay(double percentage)
{
monthlyPay = monthlyPay* percentage;
}
public String toString()
{
String result = "Name: " + getFirstName() + " " + getLastName() + "\nID: "
+ getIdNumber() + " \nHourly Rate: " + hourlyRate;
return result;
}
}
Testing class (currently testing increase
public class TestEmployee2
{
public static void main(String[] args)
{
Employee [] staff = new Employee[3];
Supervisor sup = new Supervisor("Boss", "Jim", "JB7865", 54000);
HourlyWorker hw1 = new HourlyWorker("Bee", "Busy", "BB1265", 11.95);
hw1.setHours(200);
staff[0] = sup;
staff[1] = hw1;
System.out.println(staff[0].getMonthlyPay());
staff[0].increasePay(5);
System.out.println(staff[0].getMonthlyPay());
System.out.println(staff[1].getMonthlyPay());
staff[1].increasePay(10);
System.out.println(staff[1].getMonthlyPay());
}
}
Supervisor class:
public class Supervisor extends Employee
{
private double annualSalary;
private double monthlyPay;
public Supervisor(String last, String first, String ID, double salary)
{
super(last, first, ID);
annualSalary = salary;
}
public void setAnnualSalary(double salary)
{
annualSalary = salary;
}
public double getAnnualSalary()
{
return annualSalary;
}
public double getMonthlyPay()
{
return ((annualSalary + (annualSalary * .02)) / 12);
}
public void increasePay(double percentage)
{
monthlyPay = monthlyPay* percentage;
}
public void decreasePay(double percentage)
{
monthlyPay = monthlyPay* percentage;
}
public String toString()
{
String result = "Name: " + getFirstName() + " " + getLastName() + "\nID: "
+ getIdNumber() + "\nAnnual Salary: " + annualSalary;
return result;
}
}
Output is:
4590.0 4590.0 2390.0 2390.0
Doesn't appear to be modifying getMonthlyPay()
Should be:
4590.00 4819.50 2390.00 2629.00
Generally, when implementing equals(), you compare “key” fields whose values don’t change for the entity, and don’t compare “state” fields whose values change from time to time.
You are comparing sharePrice, when I believe you should be comparing symbol.
When you do list.indexOf(temp), what that does, right now, is look for a Stock that is equals to the argument passed to it -- so it looks for a Stock with price zero, not caring about the symbol at all. That's what the code does right now.
Honestly, using indexOf and equals is not really appropriate for this problem. indexOf is really only useful when you have something that's totally equal to the target you're looking for.
The best way to do something like this is
Optional<Stock> foundStock = list.stream().filter(stock -> stock.getName().equals(symbol)).findAny();
if (foundStock.isPresent()) {
// do something with foundStock.get()
} else {
// no found stock
}
indexOf() is a method return the index of the first occurrence of the specified element in the returned list. If the list does not contain this element, value -1 is returned.
More formally, return the lowest index i that meets the following conditions:
if(o==null? get(i)==null :o.equals(get(i))){
return i;
}
return -1;
If there is no such index, return -1.
And you have override the equals method, I guess you just want to focus on the same price Stock?:
#Override
public boolean equals(Object obj){
if (obj instanceof Stock){
Stock other = (Stock) obj;
return getPrice() == other.getPrice();
}
return false;
}
As my opinion, you have use List<Stock> list so the Object in the list is all Stock. Maybe it could be simplifed:
#Override
public boolean equals(Object obj){
Stock other = (Stock) obj;
return getPrice() == other.getPrice();
}

I want to ask about exercise 11 (Level 2 Programming Exercises) in An Introduction to Object-Oriented Programming with Java (5th edition)

//My Extend Student class
public class ExtendStudent {
//data members
private String name;
private String email;
//constructor
public ExtendStudent(String StudentName, String StudentEmail){
name = StudentName;
email = StudentEmail;
}
//method
public String getName(){
return name;
}
public String getEmail(){
return email;
}
}
//My Extend Library Card class
public class ExtendLibraryCard {
//data members
private ExtendStudent owner;
private int numBorBooks;
private String expDate;
private int expDay;
private int expMonth;
private int expYear;
private boolean active;
private int thisYear;
private int thisMonth;
private int thisDay;
//constructor
public ExtendLibraryCard() {
numBorBooks = 0;
expDate = null;
expMonth = 0;
expYear = 0;
setActive(true);
}
//methods
//set the owner be the student
public void setOwner(ExtendStudent student) {
owner = student;
}
//get the name of the owner (which is the student)
public String getOwnerName() {
return owner.getName();
}
//get the email of the owner
public String getOwnerEmail(){
return owner.getEmail();
}
//number of books borrowed
public void totalBooksBorrowed(int totalBooks) {
numBorBooks = numBorBooks + totalBooks;
}
//get number of books borrowed
public int getNumBorBooks() {
return numBorBooks;
}
//print out
public String toStringExpDate() {
return "Expiration Date: " + expDay + "/" + expMonth + "/" + expYear;
}
//expiration date
public void setExpDate(int expDay, int expMonth, int expYear) {
this.expDay = expDay;
this.expMonth = expMonth;
this.expYear = expYear;
}
public int getExpMonth() {
return expMonth;
}
public void setExpMonth(int expMonth) {
this.expMonth = expMonth;
}
public int getExpYear() {
return expYear;
}
public void setExpYear(int expYear) {
this.expYear = expYear;
}
public int getExpDay() {
return expDay;
}
public void setExpDay(int expDay) {
this.expDay = expDay;
}
//set active
public void setActive(boolean state) {
active = state;
}
//getter and setter of the current time
public int getThisYear() {
return thisYear;
}
public void setThisYear(int thisYear) {
this.thisYear = thisYear;
}
public int getThisMonth() {
return thisMonth;
}
public void setThisMonth(int thisMonth) {
this.thisMonth = thisMonth;
}
public int getThisDay() {
return thisDay;
}
public void setThisDay(int thisDay) {
this.thisDay = thisDay;
}
public void testing(){
if(active = false)
System.out.println("Your card is out of date. Please buy a new one or you will not be allowed to enter the library!");
else
System.out.println(toString());
}
//print out every single info to the card
public String toString(){
return "Owner Name: " + getOwnerName() + "\n" +
"Owner Email: " +getOwnerEmail() + "\n" +
"Number of books borrowed: " + getNumBorBooks() + "\n" +
"Today: " + getThisDay() + "/" + getThisMonth() + "/" + getThisYear() + "\n" +
toStringExpDate();
}
}
//My Extend Librarian
public class ExtendLibrarian {
public static void main(String[] args) {
ExtendStudent student = new ExtendStudent("SKT Faker", "fakerskt#yahoo.com");
ExtendLibraryCard card = new ExtendLibraryCard();
card.setOwner(student);
card.getOwnerName();
card.totalBooksBorrowed(20);
card.setExpDate(20, 11, 2019);
card.setThisDay(10);
card.setThisMonth(11);
card.setThisYear(2019);
if (card.getThisYear() > card.getExpYear()) {
card.setActive(false);
} else if (card.getThisYear() == card.getExpYear()) {
if (card.getThisMonth() > card.getExpMonth()) {
card.setActive(false);
}
} else if (card.getThisYear() == card.getExpYear()) {
if (card.getThisMonth() == card.getExpMonth()) {
if (card.getThisDay() > card.getExpDay()) {
card.setActive(false);
}
}
}
else {
card.setActive(true);
}
card.testing();
}
}
So the thing is let just say my expiration day is Nov 20th 2019, and
if today is Nov 21st 2019, the code will print out "Your card is out of date", but then it's not. Can somebody help me please, thank you.
P/s: Sorry if my English is terrible
First of all in your ExtendLibraryCard Class change this line
if(active = false)
to
if (active == false)
Also in your main Librarian class change the conditions from else if to if
if (card.getThisYear() > card.getExpYear()) {
card.setActive(false);
}
if (card.getThisYear() == card.getExpYear()) {
if (card.getThisMonth() > card.getExpMonth()) {
card.setActive(false);
}
}
if (card.getThisYear() == card.getExpYear()) {
if (card.getThisMonth() == card.getExpMonth()) {
if (card.getThisDay() > card.getExpDay()) {
card.setActive(false);
}
}
} else
card.setActive(true);
card.testing();
}
Let me give you a dry run what's happening in your code:
When you have set thisYear= 2019 and ExpYear= 2019, your first else if statement is satisfied, since card.getThisYear() == card.getExpYear(), it doesn't matter even if both the month is same, greater or lesser(i.e it doesn't matter if, nested if is satisfied or not), because your getThisYear is equal to ExpThisYear and thus, 1st else if condition is satisfied, it won't check the final else if condition (which has your date checking nested if condition).
Thus setActive(false) isn't being executed.
Also since the else if condtion of this block
else if (card.getThisYear() == card.getExpYear()) {
if (card.getThisMonth() > card.getExpMonth()) {
card.setActive(false);
}
}
has been executed and it's returning true for the fist part year==year, even your else block won't be executed.
Thus it is necessary for you to change your condition to if statements because else if once condition has been met won't check other conditions unlike if.
Link : Read this for if vs else if condition vs else
Hope it helps :)

Java - Overriding A Parent Class Method

I am new to Java and I am working on a project that works with calculating prices with/without employee discounts. After reading the following code could someone explain to me how I might go about changing the parent class method outputs from the child class in order to get the correct outputs for my program?
Parent Class (I am NOT allowed to edit this):
public class GroceryBill {
private Employee clerk;
private List<Item> receipt;
private double total;
private double internalDiscount;
public GroceryBill(Employee clerk) {
this.clerk = clerk;
receipt = new ArrayList<Item>();
total = 0.0;
internalDiscount = 0.0;
}
public void add(Item i) {
receipt.add(i);
total += i.getPrice();
internalDiscount += i.getDiscount();
}
public double getTotal() {
return Math.rint(total * 100) / 100.0;
}
public Employee getClerk() {
return clerk;
}
public void printReceipt() {
System.out.println(this);
}
private String valueToString(double value) {
value = Math.rint(value * 100) / 100.0;
String result = "" + Math.abs(value);
if(result.indexOf(".") == result.length() - 2) {
result += "0";
}
result = "$" + result;
return result;
}
public String receiptToString() {
String build = "items:\n";
for(int i = 0; i < receipt.size(); i++) {
build += " " + receipt.get(i);
if(i != receipt.size() - 1) {
build += "\n";
}
}
return build;
}
public String toString() {
return receiptToString() + "\ntotal: " + valueToString(total);
}
public String discountToString() {
return receiptToString() + "\nsub-total: " + valueToString(total) + "\ndiscount: " + valueToString(internalDiscount) + "\ntotal: " + valueToString(total - internalDiscount);
}
public static class Employee {
private String name;
public Employee(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public static class Item {
private String name;
private double price;
private double discount;
public Item(String name, double price, double discount) {
this.name = name;
this.price = price;
this.discount = discount;
}
public double getPrice() {
return price;
}
public double getDiscount() {
return discount;
}
private String valueToString(double value) {
String result = "" + Math.abs(value);
if(result.indexOf(".") == result.length() - 2) {
result += "0";
}
result = "$" + result;
return result;
}
public String toString() {
return name + " " + valueToString(price) + " (-" + valueToString(discount) + ")";
}
}
}
Here is my code:
public class DiscountBill extends GroceryBill
{
private int myDiscountCount;
private double myDiscountAmount;
private double myPrice;
public DiscountBill(Employee clerk, boolean preferred)
{
super(clerk);
String name = "";
double price = 0;
double discount = 0;
Object myItem = new Item(name, price, discount);
myPrice = ((GroceryBill.Item) myItem).getPrice() - ((GroceryBill.Item) myItem).getDiscount();
GroceryBill.Item myBill = new GroceryBill.Item(name, price, discount);
myDiscountAmount = myBill.getDiscount();
if (myDiscountAmount > 0 && preferred)
{
myDiscountCount++;
}
}
/*
public double getTotal()
{
Override goes here?
}
*/
public int getDiscountCount()
{
return myDiscountCount;
}
public double getDiscountAmount()
{
return myDiscountAmount;
}
public double getDiscountPercent()
{
return (myPrice / getDiscountCount()) * 100;
}
}
Lastly, here is the expected output:
P.S. Please let me know if I need to give more/less information and ways that I can clean up this post or make it easier to understand. If my question was too broad, please ask me what you don't understand about it and I'll try my best to tell you! Thank you!

Overriding error Java, program does not read both methods only one

I have this code
public class Student extends Person {
//id represents the student's ID
private int id;
//grade represents the student's grade in the course
private Grade grade;
//constructor allows user to define first and last names, id, and grade of student in demo
public Student(String fName, String lName, int id, Grade grade) {
super(fName, lName);
this.id=id;
this.grade=grade;
}
//get methods for fields
public int getId() {
return id;
}
public Grade getGrade() {
return grade;
}
//toString prints out the string from person class along with id and grade fields in formatted string
public String toString() {
return super.toString()+"'s id is " + id + "." +getGrade();
}
}
And this code. The issue is where toString method uses the passFailGrade getGrade() return value instead of the method located within the class
public class Grade {
private double score;
public Grade(double score) {
this.score=score;
}
public void setScore(double score) {
this.score=score;
}
public double getScore() {
return score;
}
public char getGrade() {
if (getScore()>=90)
return 'A';
else if (getScore()>=80)
return 'B';
else if (getScore()>=70)
return 'C';
else if (getScore()>=60)
return 'D';
else
return 'F';
}
public String toString() {
return "\nThe student recieved a " + getGrade() +
" and had a mark of " + getScore() + ".";
}
}
Not sure if there's a problem in PassFailGrade:
public class PassFailGrade extends Grade {
public PassFailGrade(double score) {
super(score);
}
public char getGrade() {
if (getScore()>=50)
return 'Y';
else
return 'N';
}
public String toString() {
return "(Y for yes/N for no) The student passed their course ("
+ getGrade()+ ")." + super.toString();
}
}
Then demo class just defining in constructors and printing
public class StudentDemo {
public static void main(String[] args) {
PassFailGrade bo= new PassFailGrade(98);
Student s1 = new Student("bob", "blake", 123, bo);
System.out.println(s1);
}
}
Output:
bob blake's id is 123.(Y for yes/N for no) The student passed their course (Y). The student recieved a Y and had a mark of 98.0.
You're actually overriding the getGrade() method. It's something you intended to do, but now you've got a problem when you call super.toString() - it still uses your overriden methods.
You can fix this issue by changing your toString in PassFailGrade in this way:
#Override
public String toString() {
return "(Y for yes/N for no) The student passed their course ("
+ getGrade()+ ")." + "\nThe student recieved a " + super.getGrade() +
" and had a mark of " + getScore() + ".";
}
Note that I only call super.getGrade(). This will produce the correct results.

Regarding development of comparator

I have a Query I have developed a pojo ..
public class Customer {
int Age;
public Customer(int age, String surname, String forename) {
super();
Age = age;
Surname = surname;
Forename = forename;
}
String Surname,Forename;
public int getAge() {
// TODO Auto-generated method stub
return Age;
}
public String getSurname() {
// TODO Auto-generated method stub
return Surname;
}
public String getForename() {
// TODO Auto-generated method stub
return Surname;
}
public void display()
{
// System.out.println(Forename+"\t"+Surname+"\t"+Age);
System.out.println(Age+"\t"+Forename+"\t"+Surname);
}
}
and here is my collection class ..
class testCustomerComparator
{
public static void main(String... a)
{
Customer customerFirst = new Customer(46,"Alabama", "Christonson");
Customer customerSecond = new Customer(21, "Anna", "Sobek");
Customer customerThird = new Customer(27, "Rafael", "Sobek");
List<Customer> list = new ArrayList<Customer>();
list.add(customerThird);
list.add(customerSecond);
list.add(customerFirst);
}
}
please advise me How to make comprator for this class , I want to make comparator so that a list of customers get sorted by age and second by surname. After that you want to sort by forename. please advise I have nesting condition inside comparator
lOGIC MUST BE SOMETHING LIKE...
public class CustomerComparator implements Comparator<Customer> {
#Override
public int compare(Customer c1, Customer c2) {
if (c1.getAge() == c2.getAge()) {
if (c1.getSurname().compareTo(c2.getSurname()) == 0) {
return c1.getForename().compareTo(c2.getForename()) {
} else {
return c1.getSurname().compareTo(c2.getSurname());
}
} else if (c1.getAge() > b2.getAge()) {
return -1;
} else {
return 1;
}
}
but it is not working please advise
Seems much like homework. I can give you some hints in where to look at.
You have two choices:
make the POJO class extend Comparable<Customer>
define a custom external comparator as a Comparator<Customer>.
Assuming the second choice, in which you have two explicit customers, you'll have to define a method similar to this one:
#Override
public int compare(Customer c1, Customer c2)
{
// this method should return 0 if c1.equals(c2),
// should instead return 1 if c1 should come first than c2 and -1 otherwise
}
public class CustomerComparator implements Comparator<Customer> {
public int compare(Customer c1, Customer c2) {
.... here you have c1 and c2. compare returns -1 if c1 should go before c2,
0 if they are found to be equal, and 1 if c2 should go before c1.
You add the logic to compare c1 and c2 fields as you stated and return the result.
}
}
Then you use Collections.sort to sort that list using this comparator.
You can help of the below code.
import java.util.*;
class Customer {
private int age;
private String name;
private String forename;
public Customer(int age, String surname, String forename) {
super();
this.age = age;
this.name = surname;
this.forename = forename;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return this.age;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setForename(String forename) {
this.forename = forename;
}
public String getForename() {
return forename;
}
}
class AgeComparator implements Comparator {
public int compare(Object emp1, Object emp2) {
int emp1Age = ((Customer) emp1).getAge();
int emp2Age = ((Customer) emp2).getAge();
if (emp1Age > emp2Age)
return 1;
else if (emp1Age < emp2Age)
return -1;
else
return 0;
}
}
/*
* The below given comparator compares employees on the basis of their name.
*/
class NameComparator implements Comparator {
public int compare(Object emp1, Object emp2) {
// parameter are of type Object, so we have to downcast it to Employee
// objects
int emp1Age = ((Customer) emp1).getAge();
int emp2Age = ((Customer) emp2).getAge();
if (emp1Age > emp2Age) {
return 1;
} else if (emp1Age < emp2Age) {
String emp1Name = ((Customer) emp1).getName();
String emp2Name = ((Customer) emp2).getName();
// uses compareTo method of String class to compare names of the
// employee
return emp1Name.compareTo(emp2Name);
} else {
return 0;
}
}
}
class CustomerComparator implements Comparator {
public int compare(Object emp1, Object emp2) {
// parameter are of type Object, so we have to downcast it to Employee
// objects
String emp1Name = ((Customer) emp1).getName();
String emp2Name = ((Customer) emp2).getName();
// uses compareTo method of String class to compare names of the
// employee
return emp1Name.compareTo(emp2Name);
}
}
public class JavaComparatorExample {
public static void main(String args[]) {
// Employee array which will hold employees
Customer employee[] = new Customer[3];
// set different attributes of the individual employee.
employee[0] = new Customer(46, "Alabama", "Christonson");
employee[1] = new Customer(21, "Anna", "Sobek");
employee[2] = new Customer(27, "Rafael", "Sobek");
System.out.println("Order of employee before sorting is");
// print array as is.
for (int i = 0; i < employee.length; i++) {
System.out.println("Employee " + (i + 1) + " name :: "
+ employee[i].getName() + ", Age :: "
+ employee[i].getAge());
}
Arrays.sort(employee, new AgeComparator());
System.out
.println("\n\nOrder of employee after sorting by employee age is");
for (int i = 0; i < employee.length; i++) {
System.out.println("Employee " + (i + 1) + " name :: "
+ employee[i].getName() + ", Age :: "
+ employee[i].getAge());
}
// Sorting array on the basis of employee Name by passing NameComparator
Arrays.sort(employee, new NameComparator());
System.out
.println("\n\nOrder of employee after sorting by employee name is");
for (int i = 0; i < employee.length; i++) {
System.out.println("Employee " + (i + 1) + " name :: "
+ employee[i].getName() + ", Age :: "
+ employee[i].getAge());
}
}
}
Hope this will help you.
EDIT
Look at the CustomerComparator class.
#Override
public int compare(Customer c1, Customer c2) {
int r = Integer.valueOf(c1.getAge()).compareTo(c2.getAge());
if (r != 0) return r;
r = c1.getSurname().compareTo(c2.getSurname());
if (r != 0) return r;
return c1.getForename().compareTo(c2.getForename());
}

Categories

Resources