-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava_project.java
More file actions
100 lines (77 loc) · 2.56 KB
/
Java_project.java
File metadata and controls
100 lines (77 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.util.Objects;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
class Customer {
private int id;
private String firstName;
private String lastName;
private double balance;
public Customer(int id, String firstName, String lastName, double balance) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.balance = balance;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
@Override
public String toString() {
return "Customer [ID=" + id + ", First Name=" + firstName + ", Last Name=" + lastName + ", Balance=" + balance + "]";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Customer customer = (Customer) o;
return id == customer.id && Double.compare(customer.balance, balance) == 0 &&
Objects.equals(firstName, customer.firstName) && Objects.equals(lastName, customer.lastName);
}
@Override
public int hashCode() {
return Objects.hash(id, firstName, lastName, balance);
}
}
public class application
{
public static void main(String[] args) {
// Create a List of Customers
List<Customer> customers = new ArrayList<>();
customers.add(new Customer(3, "Aditya", "Kumar", 2500.50));
customers.add(new Customer(1, "Ajay", "M", 1800.75));
customers.add(new Customer(2, "Ayush", "Singh", 3000.00));
customers.add(new Customer(4, "Alex", " ", 1500.25));
System.out.println("Before Sorting:");
customers.forEach(System.out::println);
customers.sort(Comparator
.comparing(Customer::getFirstName)
.thenComparing(Customer::getLastName)
.thenComparingInt(Customer::getId)
.thenComparingDouble(Customer::getBalance));
System.out.println("\nAfter Sorting:");
customers.forEach(System.out::println);
}
}