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();

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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));
}
}

 

Ask the user for a starting point and ending point. Sort the user list using the method on the previous question but onl
Test Case 1 Falled Show what's missing
Enter a starting point and ending point\n
O 3ENTER
03EİVQZXDA
05CQW2HbejgE
OEP0CFQ
fspaldingem An
acarwithim5d \n
qgumlyq3 \n
Test Case 2 Falled Show what's missing
Enter a starting point and ending point \n
O 10 ENTER
03EİVQZXDA
05CQW2HbejgE
ØE P0CFQ
fspaldingem \n
acarwithim5d \n
qgumlyq3 \n
nmckie2w\n
zarnefieldam \n
rhutchines \n
fkeoghanjz \n
mrutigliano5r\n
kfairchild8p\n
slaverock30\n
ØFVyno
Øh8Q9YUY9
Øk750fqrj5e
OP55sxs
Ør1Hkgaq6xBw
Øsug8D4
øtfzt1
Test Case 3 Falled
Show what's missing
Enter a starting point and ending point \n
10 30 ENTER
mrallings9b\n
jryallq\n
rchallenorlg \n
mieldeng9 \n
mdudlestonb6 \n
pcowenq2 \n
mphlippibp \n
ocaughandt \n
nbindon71\n
ckupperce\n
cgurradok3 \n
arawcliffja\n
cdarteran \n
cguitel3y\n
zrodderp\n
dbrighamdc \n
balgaterl\n
dmetzelos \n
tlyffe5s \n
mgolderol \n
ØVGFGLW8L64T
ØWYSkh3m
Øx420432E
ØYhBkYQad5j
ØYZJIKI2RS8
15TUF956
19J0sob
19WZBAHFXCG
1BhokzCb
1CIgzsFUR
1h161gozQ
1j3deRzE4
1JcCDpdV
1Joqx1Zi6ovv
1NJDHPKYZ10
1QZP9K7SV9B
1uQGHD9a
1vCqgfn3
1VJ5GYXT
1WUBPJREFSY
Test Case 4 Falled Show what's missing C
Transcribed Image Text:Ask the user for a starting point and ending point. Sort the user list using the method on the previous question but onl Test Case 1 Falled Show what's missing Enter a starting point and ending point\n O 3ENTER 03EİVQZXDA 05CQW2HbejgE OEP0CFQ fspaldingem An acarwithim5d \n qgumlyq3 \n Test Case 2 Falled Show what's missing Enter a starting point and ending point \n O 10 ENTER 03EİVQZXDA 05CQW2HbejgE ØE P0CFQ fspaldingem \n acarwithim5d \n qgumlyq3 \n nmckie2w\n zarnefieldam \n rhutchines \n fkeoghanjz \n mrutigliano5r\n kfairchild8p\n slaverock30\n ØFVyno Øh8Q9YUY9 Øk750fqrj5e OP55sxs Ør1Hkgaq6xBw Øsug8D4 øtfzt1 Test Case 3 Falled Show what's missing Enter a starting point and ending point \n 10 30 ENTER mrallings9b\n jryallq\n rchallenorlg \n mieldeng9 \n mdudlestonb6 \n pcowenq2 \n mphlippibp \n ocaughandt \n nbindon71\n ckupperce\n cgurradok3 \n arawcliffja\n cdarteran \n cguitel3y\n zrodderp\n dbrighamdc \n balgaterl\n dmetzelos \n tlyffe5s \n mgolderol \n ØVGFGLW8L64T ØWYSkh3m Øx420432E ØYhBkYQad5j ØYZJIKI2RS8 15TUF956 19J0sob 19WZBAHFXCG 1BhokzCb 1CIgzsFUR 1h161gozQ 1j3deRzE4 1JcCDpdV 1Joqx1Zi6ovv 1NJDHPKYZ10 1QZP9K7SV9B 1uQGHD9a 1vCqgfn3 1VJ5GYXT 1WUBPJREFSY Test Case 4 Falled Show what's missing C
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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY