SlideShare a Scribd company logo
1 of 4
Download to read offline
Below is my code for a line editor:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static List lines = new ArrayList();
public static void main(String[] args) throws IOException
{
Scanner s = new Scanner(System.in);
System.out.print("Input file: ");
String fileName = s.nextLine();
BufferedReader br = new BufferedReader(new FileReader(new File(fileName)));
String str="";
int count=0;
while((str=br.readLine())!=null)
{
lines.add(count, str);
System.out.println((++count) + "> "+ str);
}
String text="";
String command = "";
System.out.print((++count)+"> ");
command=s.nextLine();
String commandArr[];
int flag;
while(!command.equals("E"))
{
flag=0;
commandArr = command.split("s");
if(commandArr[0].equals("I")) //Insertion
{
while(true)
{
if(commandArr.length==1&&flag!=2)
{
System.out.print((count)+"> ");
text = s.nextLine();
insertLine(text,count-1);
}
else if(commandArr.length==2&&flag!=2)
{
System.out.print((commandArr[1])+"> ");
count=Integer.parseInt(commandArr[1]);
text = s.nextLine();
insertLine(text,Integer.parseInt(commandArr[1])-1);
}
else
insertLine(text,count-1);
System.out.print((++count)+"> ");
command=s.nextLine();
commandArr = command.split("s");
if(commandArr[0].equals("I")||commandArr[0].equals("L")||commandArr[0].equals("D")||comm
andArr[0].equals("E"))
{
flag=1;
break;
}
else
{
flag=2;
text=command;
}
}
}
else if(commandArr[0].equals("L")) //Listing
{
printList();
}
else if(commandArr[0].equals("D")) //Deletion
{
if(commandArr.length==1)
{
deleteLine(count-1,count-1);
}
else if(commandArr.length==2)
{
deleteLine(Integer.parseInt(commandArr[1])-1,Integer.parseInt(commandArr[1])-1);
}
else if(commandArr.length==3)
{
deleteLine(Integer.parseInt(commandArr[1])-1,Integer.parseInt(commandArr[2])-1);
}
count=lines.size();
}
if(flag!=1)
{
System.out.print((count++)+"> ");
command = s.nextLine();
}
}
}
public static void insertLine(String text,int count)
{
lines.add(count,text);
}
public static void deleteLine(int start,int end)
{
for(int i=start;i<=end;i++)
lines.remove(i);
}
public static void printList()
{
for(int i=0;i "+lines.get(i));
}
}
The output should look like this:
EDIT: textin.txt (user inputs textin.txt)
1> The first line
2>
3> And another line
4> I 3
3> The second line
4> One more line
5> L
1> The first line
2>
3> The second line
4> One more line
5> And another line //This is now line 5; not 3;
5> D 2 // line 5, since L was issued from line 5;
4> L //line 4, since one line was deleted;
1> The first line
2> The second line
3> One more line
4> And another line
5> E
Here is a screenshot of the errors I am getting and need help fixing them: FileEdit [Java
Application] /Users/caseysharp/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.mac
EDIT: textin.txt 1> The First line 1> 2> And another line 3> I 3 3> The second line Exception in
thread "main" java. lang, Index0utofBoundsException: Index: 2, Size: 0 at java. base/ java. util.
ArrayList, rangeCheckForAdd (ArrayList,java: 756) at java. base/ java. util. ArrayList, add
(ArrayList,java:481) at FileEdit, insertLine (FileEdit, java: 198) at FileEdit, main (FileEdit,
java:102)

More Related Content

Similar to Below is my code for a line editor import java.io.BufferedReader;.pdf

CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfpremsrivastva8
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfanurag1231
 
Cifrado cesar
Cifrado cesarCifrado cesar
Cifrado cesarEIYSC
 
import java.io.BufferedReader; import java.io.IOException; impor.pdf
import java.io.BufferedReader; import java.io.IOException; impor.pdfimport java.io.BufferedReader; import java.io.IOException; impor.pdf
import java.io.BufferedReader; import java.io.IOException; impor.pdfaravlitraders2012
 
InsertionSorting.javaimport java.util.Arrays; import java.util.S.pdf
InsertionSorting.javaimport java.util.Arrays; import java.util.S.pdfInsertionSorting.javaimport java.util.Arrays; import java.util.S.pdf
InsertionSorting.javaimport java.util.Arrays; import java.util.S.pdfinfo54093
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into itmelakusisay507
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
Write a java program that reads a number N as input and displays the.pdf
Write a java program that reads a number N as input and displays the.pdfWrite a java program that reads a number N as input and displays the.pdf
Write a java program that reads a number N as input and displays the.pdfbrijeshagarwa329898l
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfFootageetoffe16
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docxajoy21
 
Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docxnoreendchesterton753
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 

Similar to Below is my code for a line editor import java.io.BufferedReader;.pdf (20)

CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdfCountStringCharacters.javaimport java.util.Scanner; public cla.pdf
CountStringCharacters.javaimport java.util.Scanner; public cla.pdf
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
 
Lab4
Lab4Lab4
Lab4
 
Cifrado cesar
Cifrado cesarCifrado cesar
Cifrado cesar
 
import java.io.BufferedReader; import java.io.IOException; impor.pdf
import java.io.BufferedReader; import java.io.IOException; impor.pdfimport java.io.BufferedReader; import java.io.IOException; impor.pdf
import java.io.BufferedReader; import java.io.IOException; impor.pdf
 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
 
InsertionSorting.javaimport java.util.Arrays; import java.util.S.pdf
InsertionSorting.javaimport java.util.Arrays; import java.util.S.pdfInsertionSorting.javaimport java.util.Arrays; import java.util.S.pdf
InsertionSorting.javaimport java.util.Arrays; import java.util.S.pdf
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into it
 
The Art of Clean Code
The Art of Clean CodeThe Art of Clean Code
The Art of Clean Code
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Write a java program that reads a number N as input and displays the.pdf
Write a java program that reads a number N as input and displays the.pdfWrite a java program that reads a number N as input and displays the.pdf
Write a java program that reads a number N as input and displays the.pdf
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Prompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdfPrompt a user to enter a series of integers separated by spaces and .pdf
Prompt a user to enter a series of integers separated by spaces and .pdf
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docx
 
Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
 
Computer programming 2 chapter 1-lesson 2
Computer programming 2  chapter 1-lesson 2Computer programming 2  chapter 1-lesson 2
Computer programming 2 chapter 1-lesson 2
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 

More from alankarshoe84

Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdfBir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdfalankarshoe84
 
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdfBir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdfalankarshoe84
 
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdfBir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdfalankarshoe84
 
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdfBilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdfalankarshoe84
 
Beyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdfBeyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdfalankarshoe84
 
Better technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdfBetter technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdfalankarshoe84
 
Bernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdfBernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdfalankarshoe84
 
Berger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdfBerger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdfalankarshoe84
 
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdfBen - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdfalankarshoe84
 
C Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdfC Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdfalankarshoe84
 
C Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdfC Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdfalankarshoe84
 
C Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdfC Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdfalankarshoe84
 
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdfB�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdfalankarshoe84
 
C language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdfC language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdfalankarshoe84
 
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdfB�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdfalankarshoe84
 
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdfB�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdfalankarshoe84
 
business information systems (a). Explain three opportunities and.pdf
business information systems  (a). Explain three opportunities and.pdfbusiness information systems  (a). Explain three opportunities and.pdf
business information systems (a). Explain three opportunities and.pdfalankarshoe84
 
business information systems 1. Explain the five components of an.pdf
business information systems  1. Explain the five components of an.pdfbusiness information systems  1. Explain the five components of an.pdf
business information systems 1. Explain the five components of an.pdfalankarshoe84
 
Below is a C code that serves as a handwritten lexical analyzer on a.pdf
Below is a C code that serves as a handwritten lexical analyzer on a.pdfBelow is a C code that serves as a handwritten lexical analyzer on a.pdf
Below is a C code that serves as a handwritten lexical analyzer on a.pdfalankarshoe84
 
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdfBuenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdfalankarshoe84
 

More from alankarshoe84 (20)

Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdfBir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
Bir proje y�neticisi, paydalarn yeni bir proje i�in farkl beklentile.pdf
 
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdfBir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
Bir banka dekontu A. irketin hesap bakiyesini artran veya azaltan .pdf
 
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdfBir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
Bir aratrmac, korku filmleri izlerken insanlarn fizyolojik tepkileri.pdf
 
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdfBilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
Bilgisayar yerine cep telefonlar, tbbi cihazlar ve t�ketici elektron.pdf
 
Beyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdfBeyond the miners, their families, investors and the Peruvian govern.pdf
Beyond the miners, their families, investors and the Peruvian govern.pdf
 
Better technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdfBetter technology in one country results in Multiple Choice a countr.pdf
Better technology in one country results in Multiple Choice a countr.pdf
 
Bernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdfBernard Lawrence Bernie Madoff was an American financier who execu.pdf
Bernard Lawrence Bernie Madoff was an American financier who execu.pdf
 
Berger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdfBerger y Luckmann afirman que nacemos en una estructura social obje.pdf
Berger y Luckmann afirman que nacemos en una estructura social obje.pdf
 
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdfBen - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
Ben - Satisfy the individuals need for affiliation Analyse-Develop,.pdf
 
C Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdfC Programming LanguageHello can i please get help understanding ho.pdf
C Programming LanguageHello can i please get help understanding ho.pdf
 
C Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdfC Language PLEASE Write a C program that inputs a line of text.pdf
C Language PLEASE Write a C program that inputs a line of text.pdf
 
C Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdfC Language PLEASE Write a C program to create a dynamic array. T.pdf
C Language PLEASE Write a C program to create a dynamic array. T.pdf
 
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdfB�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
B�y�k bir kuruluta, dahili veri kaynaklarnn y�netimine y�nelik polit.pdf
 
C language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdfC language in visual studios with comments1) use standard inputou.pdf
C language in visual studios with comments1) use standard inputou.pdf
 
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdfB�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
B�t�elerle ilgili olarak aadaki ifadelerden hangisi doru DELDR A..pdf
 
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdfB�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
B�l�m B � Nehir Sistemlerine Genel Bak Nehirler ve akarsular bir d.pdf
 
business information systems (a). Explain three opportunities and.pdf
business information systems  (a). Explain three opportunities and.pdfbusiness information systems  (a). Explain three opportunities and.pdf
business information systems (a). Explain three opportunities and.pdf
 
business information systems 1. Explain the five components of an.pdf
business information systems  1. Explain the five components of an.pdfbusiness information systems  1. Explain the five components of an.pdf
business information systems 1. Explain the five components of an.pdf
 
Below is a C code that serves as a handwritten lexical analyzer on a.pdf
Below is a C code that serves as a handwritten lexical analyzer on a.pdfBelow is a C code that serves as a handwritten lexical analyzer on a.pdf
Below is a C code that serves as a handwritten lexical analyzer on a.pdf
 
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdfBuenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
Buenaventura B�y�me, Perunun �nde gelen madencilik irketi ve d�ny.pdf
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

Below is my code for a line editor import java.io.BufferedReader;.pdf

  • 1. Below is my code for a line editor: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static List lines = new ArrayList(); public static void main(String[] args) throws IOException { Scanner s = new Scanner(System.in); System.out.print("Input file: "); String fileName = s.nextLine(); BufferedReader br = new BufferedReader(new FileReader(new File(fileName))); String str=""; int count=0; while((str=br.readLine())!=null) { lines.add(count, str); System.out.println((++count) + "> "+ str); } String text=""; String command = ""; System.out.print((++count)+"> "); command=s.nextLine(); String commandArr[]; int flag; while(!command.equals("E")) { flag=0; commandArr = command.split("s"); if(commandArr[0].equals("I")) //Insertion {
  • 2. while(true) { if(commandArr.length==1&&flag!=2) { System.out.print((count)+"> "); text = s.nextLine(); insertLine(text,count-1); } else if(commandArr.length==2&&flag!=2) { System.out.print((commandArr[1])+"> "); count=Integer.parseInt(commandArr[1]); text = s.nextLine(); insertLine(text,Integer.parseInt(commandArr[1])-1); } else insertLine(text,count-1); System.out.print((++count)+"> "); command=s.nextLine(); commandArr = command.split("s"); if(commandArr[0].equals("I")||commandArr[0].equals("L")||commandArr[0].equals("D")||comm andArr[0].equals("E")) { flag=1; break; } else { flag=2; text=command; } } } else if(commandArr[0].equals("L")) //Listing { printList();
  • 3. } else if(commandArr[0].equals("D")) //Deletion { if(commandArr.length==1) { deleteLine(count-1,count-1); } else if(commandArr.length==2) { deleteLine(Integer.parseInt(commandArr[1])-1,Integer.parseInt(commandArr[1])-1); } else if(commandArr.length==3) { deleteLine(Integer.parseInt(commandArr[1])-1,Integer.parseInt(commandArr[2])-1); } count=lines.size(); } if(flag!=1) { System.out.print((count++)+"> "); command = s.nextLine(); } } } public static void insertLine(String text,int count) { lines.add(count,text); } public static void deleteLine(int start,int end) { for(int i=start;i<=end;i++) lines.remove(i); } public static void printList() { for(int i=0;i "+lines.get(i));
  • 4. } } The output should look like this: EDIT: textin.txt (user inputs textin.txt) 1> The first line 2> 3> And another line 4> I 3 3> The second line 4> One more line 5> L 1> The first line 2> 3> The second line 4> One more line 5> And another line //This is now line 5; not 3; 5> D 2 // line 5, since L was issued from line 5; 4> L //line 4, since one line was deleted; 1> The first line 2> The second line 3> One more line 4> And another line 5> E Here is a screenshot of the errors I am getting and need help fixing them: FileEdit [Java Application] /Users/caseysharp/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.mac EDIT: textin.txt 1> The First line 1> 2> And another line 3> I 3 3> The second line Exception in thread "main" java. lang, Index0utofBoundsException: Index: 2, Size: 0 at java. base/ java. util. ArrayList, rangeCheckForAdd (ArrayList,java: 756) at java. base/ java. util. ArrayList, add (ArrayList,java:481) at FileEdit, insertLine (FileEdit, java: 198) at FileEdit, main (FileEdit, java:102)