0% found this document useful (0 votes)
96 views

Import Java - Util.

The document contains Java code that takes user input to create User objects with a username and bank name. It stores the Users in a Set and List. It then takes a comma separated list of usernames as input and finds the matching Users that will expire within a month, adding them to an expireList. It sorts and prints out the details of each User in the expireList.

Uploaded by

Vipul Ajmera
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Import Java - Util.

The document contains Java code that takes user input to create User objects with a username and bank name. It stores the Users in a Set and List. It then takes a comma separated list of usernames as input and finds the matching Users that will expire within a month, adding them to an expireList. It sorts and prints out the details of each User in the expireList.

Uploaded by

Vipul Ajmera
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

*;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number of users:");
int n = scanner.nextInt();
scanner.nextLine();

Set<User> users = new HashSet<>();


List<User> userList = new ArrayList<>();

for (int i = 1; i <= n; i++) {


System.out.println("Enter details of user" + i);
System.out.println("Username:");
String username = scanner.nextLine();
System.out.println("Bank name:");
String bankname = scanner.nextLine();
User user = new User(username, bankname);
users.add(user);
userList.add(user);
}

System.out.println("Enter username(Expire in one month) seperated by


comma");
String[] expireUsers = scanner.nextLine().split(",");
List<User> expireList = new ArrayList<>();

for (String expireUser : expireUsers) {


for (User user : users) {
if (user.getUsername().equals(expireUser)) {
expireList.add(user);
break;
}
}
}

users.retainAll(expireList);
Collections.sort(expireList);

System.out.println("Users going to expire within a month");

for (int i = 0; i < expireList.size(); i++) {


User user = expireList.get(i);
System.out.println("User " + (i + 1));
System.out.println("User Name = " + user.getUsername());
System.out.println("Bank Name = " + user.getBankname());
}
}
}

You might also like