In Java. Ask the user for a starting point and ending point. Sort the user list using the method in the previous question, but only display the users within the entered range. I already have a code, but it doesn't sort right. I believe there is something wrong. Here is the data text. I can't copy and paste it because it is too long. https://textuploader.com/t1ol7 The image without the red highlight should be the correct output. Code: import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class Users { public static void main(String[] args){ String filename = "user-database.txt"; Scanner infile = null; try { infile = new Scanner(new File(filename)); } catch (FileNotFoundException e) { System.out.println(e.getMessage()); } ArrayList usernames = new ArrayList(); ArrayList passwords = new ArrayList(); int start, end; Scanner input = new Scanner(System.in); System.out.println("Enter a starting point and ending point"); start = input.nextInt(); end = input.nextInt(); infile.nextLine();
In Java. Ask the user for a starting point and ending point. Sort the user list using the method in the previous question, but only display the users within the entered range. I already have a code, but it doesn't sort right. I believe there is something wrong.
Here is the data text. I can't copy and paste it because it is too long. https://textuploader.com/t1ol7
The image without the red highlight should be the correct output.
Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Users
{
public static void main(String[] args){
String filename = "user-database.txt";
Scanner infile = null;
try {
infile = new Scanner(new File(filename));
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
ArrayList usernames = new ArrayList();
ArrayList passwords = new ArrayList();
int start, end;
Scanner input = new Scanner(System.in);
System.out.println("Enter a starting point and ending point");
start = input.nextInt();
end = input.nextInt();
infile.nextLine();
while(infile.hasNext()){
usernames.add(infile.next());
passwords.add(infile.next());
}
infile.close();
int minIdx;
String temp;
for(int i = 0; i < passwords.size();i++){
minIdx = i;
for(int j = i+1; j < passwords.size(); j++){
if(passwords.get(j).compareToIgnoreCase(passwords.get(minIdx)) < 0)
minIdx = j;
}
temp = passwords.get(i);
passwords.set(i, passwords.get(minIdx));
passwords.set(minIdx, temp);
temp = usernames.get(i);
usernames.set(i, usernames.get(minIdx));
usernames.set(minIdx, temp);
}
for(int i = start; i < usernames.size() && i < end; i++)
System.out.printf("%20s %20s\n", passwords.get(i), usernames.get(i));
}
}

![Test Case 1 Falled Show what's missing
Enter a starting point and ending point\n
O 3 ENTER
nmckie2w\n]
slaverock30 \n
csidsaffks \n
OFVyno
Otfzt1
24iDoX
Test Case 2 Falled Show what's missing
Enter a starting point and ending point \n
0 10ΕNTE
nmckie2w\n
slaverock30\n
csidsaffks \n
cdewsr4|\n
scharnick7y \n
egeane5y \n
dbellie6y\n
bpfaffelm9\n
bsilver9f\n
kdossantose1\n
OFVyno
øtfzt1
24iDoX
2bq4TN
2qywQ7
2YNPLE
2zSD6b
3Hqa6U
3rEDDI
4iFm02
Test Case 3 Falled Show what's missing
Enter a starting point and ending point \n
10 30 ENTER
skristoffersen4q[\n]
gdagleas2g \n
1commuzzoog \n
ckeatleyqv \n
gmcrannellgm\n
askilleno1 \n
ploomis8w\n
krollinsonro \n
beagleton70 \n
4y55b1
5mvd0B
5UGUSP
6Li0xh
6qzb61
6SipcG
6UBR8S
75охх0
7MKYR4
wself13 \n
sgudyer9d \n
Cwallentinl7 \n
1fortnam97 \n
jhuardbj \n
groberdsx \n
esutty9j \n
cputtonav\n
1breese3d \n
sslyfordei \n
echetwynd5m \n
7r91t8
7tK180
99Uolo
9ilTKz
9PBCN9
9RiøYa
AiMpbu
aqyvIA
Aгохом
AvamJH
Test Case 4 Falled
Show what's missing](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa6e022be-0b69-47c9-842b-df15c0464427%2F27fe693d-41fb-4fa4-af64-d352677411ae%2Fiy5rdri_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









