CAN AN EXPERT HELP FIX MY CODE here is my code import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class User implements Comparable { private String username; private String password; public User(String username, String password) { this.username = username; this.password = password; } @Override public int compareTo(User other) { int cmp = this.password.length() - other.password.length(); if (cmp != 0) { return cmp; } cmp = this.password.toLowerCase().compareTo(other.password.toLowerCase()); if (cmp != 0) { return cmp; } return this.username.toLowerCase().compareTo(other.username.toLowerCase()); } @Override public String toString() { return String.format("%20s%20s", password, username); } public static void main(String args[]){ List l= new ArrayList<>(); try{ BufferedReader br= new BufferedReader(new FileReader(new File("user-database.txt"))); String st, username, password; while((st=br.readLine())!=null){ username= st.split("\t")[0]; password= st.split("\t")[1]; l.add(new User(username,password)); } br.close(); BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); Collections.sort(l); System.out.println("Enter a starting point and ending point"); String inp[]= in.readLine().trim().split(" "); int start= Integer.parseInt(inp[0]); int end= Integer.parseInt(inp[1]); for(int i=start;i l.size()) { end = l.size(); } for (int i = start; i < end; i++) { User u = l.get(i); System.out.println(u); } but those solutions do not work, can another solution be provided to help fix my code, can an expert help fix my code so that it starts on the second line by removing the first line in bold and adding the last line in bold to display correctly, I am just one line off

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

CAN AN EXPERT HELP FIX MY CODE

here is my code

import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class User implements Comparable<User> { private String username; private String password; public User(String username, String password) { this.username = username; this.password = password; } @Override public int compareTo(User other) { int cmp = this.password.length() - other.password.length(); if (cmp != 0) { return cmp; } cmp = this.password.toLowerCase().compareTo(other.password.toLowerCase()); if (cmp != 0) { return cmp; } return this.username.toLowerCase().compareTo(other.username.toLowerCase()); } @Override public String toString() { return String.format("%20s%20s", password, username); } public static void main(String args[]){ List<User> l= new ArrayList<>(); try{ BufferedReader br= new BufferedReader(new FileReader(new File("user-database.txt"))); String st, username, password; while((st=br.readLine())!=null){ username= st.split("\t")[0]; password= st.split("\t")[1]; l.add(new User(username,password)); } br.close(); BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); Collections.sort(l); System.out.println("Enter a starting point and ending point"); String inp[]= in.readLine().trim().split(" "); int start= Integer.parseInt(inp[0]); int end= Integer.parseInt(inp[1]); for(int i=start;i<end;i++){ User u= l.get(i); System.out.println(u); } } catch(IOException e){ System.out.println(e.getMessage()); } } }

it should display

Enter a starting point and ending point\n
493 562ENTER
fpCqTjEfk cjacmardpr\n
gAmfepkQX cbidgodc4\n
GheSmEhte pianillipm\n
GMHoz13Ko lmcamishdl\n
Gr3yzaUYQ sheeranc8\n
Gv2zAbRx6 tcraddy8c\n
h7FUxSdUz rrosingb\n
HDLFE0tEN rfryd1l\n
HIlCcbD87 htongo8\n
hXB6xBgNW bfogdeneg\n
HzqustkgH mhansardpv\n
I44S3hCp9 ydranfield80\n
IE749MAQu dhouseman9a\n....

TJyeWJWUv bneamesmm\n
TLONniHHE aaltyok\n
tpXu8iQGW bwillimotcu\n
tQ8JiPSD5 ecurrorbu\n //adding this line to replace the first line but at the bottom 

 

however. it is off one line and producing an extra line in the beginning and lacks a line at the end and instead displays:

Enter a starting point and ending point\n
493 562ENTER
fMTEc9nPe smcconway7w\n //please remove this line so it starts on the next one
fpCqTjEfk cjacmardpr\n
gAmfepkQX cbidgodc4\n
GheSmEhte pianillipm\n
GMHoz13Ko lmcamishdl\n
Gr3yzaUYQ sheeranc8\n
Gv2zAbRx6 tcraddy8c\n
h7FUxSdUz rrosingb\n
HDLFE0tEN rfryd1l\n
HIlCcbD87 htongo8\n
hXB6xBgNW bfogdeneg\n
HzqustkgH mhansardpv\n
I44S3hCp9 ydranfield80\n
IE749MAQu dhouseman9a\n
IWA54iHTY ddongallp2\n...
TJyeWJWUv bneamesmm\n
TLONniHHE aaltyok\n
tpXu8iQGW bwillimotcu\n

i have tried changing 

for(int i=start;i<end;i++){
User u= l.get(i);
System.out.println(u);
}

to 

for(int i=start;i<=end;i++){
User u= l.get(i);
System.out.println(u);

and 

for(int i=start-1;i<end;i++){
User u= l.get(i);
System.out.println(u);
}

and i have tried changing loop iterations 

if (end > l.size()) {
end = l.size();
}
for (int i = start; i < end; i++) {
User u = l.get(i);
System.out.println(u);
}

but those solutions do not work, can another solution be provided to help fix my code, can an expert help fix my code so that it starts on the second line by removing the first line in bold and adding the last line in bold to display correctly, I am just one line off

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education