SlideShare a Scribd company logo
1 of 5
Download to read offline
Hi, I need help with a java programming project. specifically practice Program number 2 on page
809 from chapter 10 of the 7th edition of the book , java:an introduction to problem solving and
programming. it tells me to Write a program that reads a file of number of type int and outputs
all the numbers to another file, but without
any duplicate numbers. Assume that the input file is sorted from smallest first to largest last.
After
the program is run, the new file will contain all the numbers in the original file, but no number
will appear more than
once in the file. The numbers in the output file should also be sorted from smallest to largest.
Your program
should obtain both file names from the user. For the text-file version, the file should be a text
file with one number
per line. For the binary-file version, the file should be binary file that consists entirely of
numbers of type int
that were written using writeInt.
I have written a program that technically runs , but i cant get it to create an output file that
displays the needed numbers.
Here is my code
import java.lang.*;
import java.io.*; ///required packages
import java.util.*;
public class RemoveDuplicate
{
public static void main (String args []) throws Exception
{
int count = 0;
String line;
String newLine = System.getProperty("line.seperator"); //gets line seperator for system
System.out.print(" enter input file name"); // taking original file name from user
Scanner scanner = new Scanner(System.in);
String fileNameOld = scanner.next(); //reads original file name
System.out.print(" enter output file name"); // takes name of new file from user
String fileNameNew = scanner.next();
File file = new File (fileNameNew); // creates file object
PrintWriter out = new PrintWriter (new FileWriter(file)); //creates printwriter object
Scanner scanFile = new Scanner (new File(fileNameOld)); //creates scanner object for reading
file
int temp = 0;
while(scanFile.hasNextLine()) // while numbers are in file
{
line = scanFile.nextLine(); // reads number
int number = Integer.parseInt(line);// converts numbers to int value
if(count == 0)
{
out.write(Integer.toString(number));
out.write(newLine);
temp = number;
count ++ ; //increment count
}
else
{
if (temp != number)
{
out.write(Integer.toString(number));
out.write(newLine);
temp = number;
}
}
}
out.close(); // closes stream
}
}
For reference I need to make it read an input txt/notepad file called numbers.txt which has
numbers that look like following
and get it to produce an output file called output.txt, which looks like the following
Any help would immensly be appreciated. 12 33 33 178 239 1254 11245 x https://bb courses n x
f Facebook x C Chegg Study IGuid X Hi, I Need Help Wit x C https://bb.courses.main /courses
/1/1710. UMS03-C.0006 1/content/ 1873037 1/numbers.txt e.edu OM x D HMWK7 Screenshot
x 5:34 PM 11/28/2016
Solution
RemoveDuplicate.java
import java.lang.*;
import java.io.*; ///required packages
import java.util.*;
public class RemoveDuplicate
{
public static void main (String args []) throws Exception
{
int count = 0;
String line;
String newLine = System.getProperty("line.seperator"); //gets line seperator for system
System.out.print(" enter input file name"); // taking original file name from user
Scanner scanner = new Scanner(System.in);
String fileNameOld = scanner.next(); //reads original file name
System.out.print(" enter output file name"); // takes name of new file from user
String fileNameNew = scanner.next();
File file = new File (fileNameNew); // creates file object
PrintWriter out = new PrintWriter (new FileWriter(file)); //creates printwriter object
Scanner scanFile = new Scanner (new File(fileNameOld)); //creates scanner object for reading
file
int temp = 0;
while(scanFile.hasNextLine()) // while numbers are in file
{
line = scanFile.nextLine(); // reads number
int number = Integer.parseInt(line);// converts numbers to int value
if(count == 0)
{
out.write(Integer.toString(number));
out.write(" ");
temp = number;
count ++ ; //increment count
}
else
{
if (temp != number)
{
out.write(Integer.toString(number));
out.write(" ");
temp = number;
}
}
System.out.println(number);
}
out.close(); // closes stream
}
}
Output:
enter input file nameD: umbers.txt
enter output file nameD:output.txt
2
3
4
12
33
178
239
1254
11245

More Related Content

Similar to Hi, I need help with a java programming project. specifically practi.pdf

The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfanjanacottonmills
 
Input output files in java
Input output files in javaInput output files in java
Input output files in javaKavitha713564
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OWebStackAcademy
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4Sunil OS
 
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
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxmichael1810
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfshahidqamar17
 
Please include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdfPlease include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdffashionfootwear1
 
Program reads in a file of phone numbers without area codes .pdf
Program reads in a file of phone numbers without area codes  .pdfProgram reads in a file of phone numbers without area codes  .pdf
Program reads in a file of phone numbers without area codes .pdfnitinarora01
 
I need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdfI need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdfsales98
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and OutputEduardo Bergavera
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12Vince Vo
 
ch06-file-processing.ppt
ch06-file-processing.pptch06-file-processing.ppt
ch06-file-processing.pptMahyuddin8
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdfSudhanshiBakre1
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfdeepaksatrker
 

Similar to Hi, I need help with a java programming project. specifically practi.pdf (20)

The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdf
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
 
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
 
CORE JAVA-1
CORE JAVA-1CORE JAVA-1
CORE JAVA-1
 
Lab4
Lab4Lab4
Lab4
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 
Create a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdfCreate a text file named lnfo.txt. Enter the following informatio.pdf
Create a text file named lnfo.txt. Enter the following informatio.pdf
 
srgoc
srgocsrgoc
srgoc
 
Java practical
Java practicalJava practical
Java practical
 
Please include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdfPlease include comments if at all possible Use a socket connection t.pdf
Please include comments if at all possible Use a socket connection t.pdf
 
Program reads in a file of phone numbers without area codes .pdf
Program reads in a file of phone numbers without area codes  .pdfProgram reads in a file of phone numbers without area codes  .pdf
Program reads in a file of phone numbers without area codes .pdf
 
I need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdfI need help with this Java assignment. Please include comments throu.pdf
I need help with this Java assignment. Please include comments throu.pdf
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12
 
ch06-file-processing.ppt
ch06-file-processing.pptch06-file-processing.ppt
ch06-file-processing.ppt
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdf
 

More from PRATIKSINHA7304

Find the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdfFind the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdfPRATIKSINHA7304
 
A new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfA new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfPRATIKSINHA7304
 
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfAre these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfPRATIKSINHA7304
 
1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdfPRATIKSINHA7304
 
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdfPRATIKSINHA7304
 
You are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdfYou are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdfPRATIKSINHA7304
 
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfwrite a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfPRATIKSINHA7304
 
Wiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfWiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfPRATIKSINHA7304
 
Which of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfWhich of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfPRATIKSINHA7304
 
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdfPRATIKSINHA7304
 
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfWhat are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfPRATIKSINHA7304
 
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdfWhat led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdfPRATIKSINHA7304
 
What is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfWhat is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfPRATIKSINHA7304
 
What factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdfWhat factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdfPRATIKSINHA7304
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfPRATIKSINHA7304
 
this is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfthis is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfPRATIKSINHA7304
 
This fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdfThis fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdfPRATIKSINHA7304
 
The term refers to a. Global Analysis of the proteins produced in .pdf
The term  refers to  a. Global Analysis of the proteins produced in .pdfThe term  refers to  a. Global Analysis of the proteins produced in .pdf
The term refers to a. Global Analysis of the proteins produced in .pdfPRATIKSINHA7304
 
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdfThe inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdfPRATIKSINHA7304
 

More from PRATIKSINHA7304 (20)

Find the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdfFind the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdf
 
A new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfA new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdf
 
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfAre these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
 
1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf
 
[10 points]Add the.pdf
[10 points]Add the.pdf[10 points]Add the.pdf
[10 points]Add the.pdf
 
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
 
You are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdfYou are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdf
 
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfwrite a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
 
Wiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfWiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdf
 
Which of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfWhich of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdf
 
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
 
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfWhat are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
 
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdfWhat led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
 
What is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfWhat is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdf
 
What factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdfWhat factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdf
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
 
this is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfthis is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdf
 
This fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdfThis fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdf
 
The term refers to a. Global Analysis of the proteins produced in .pdf
The term  refers to  a. Global Analysis of the proteins produced in .pdfThe term  refers to  a. Global Analysis of the proteins produced in .pdf
The term refers to a. Global Analysis of the proteins produced in .pdf
 
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdfThe inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Hi, I need help with a java programming project. specifically practi.pdf

  • 1. Hi, I need help with a java programming project. specifically practice Program number 2 on page 809 from chapter 10 of the 7th edition of the book , java:an introduction to problem solving and programming. it tells me to Write a program that reads a file of number of type int and outputs all the numbers to another file, but without any duplicate numbers. Assume that the input file is sorted from smallest first to largest last. After the program is run, the new file will contain all the numbers in the original file, but no number will appear more than once in the file. The numbers in the output file should also be sorted from smallest to largest. Your program should obtain both file names from the user. For the text-file version, the file should be a text file with one number per line. For the binary-file version, the file should be binary file that consists entirely of numbers of type int that were written using writeInt. I have written a program that technically runs , but i cant get it to create an output file that displays the needed numbers. Here is my code import java.lang.*; import java.io.*; ///required packages import java.util.*; public class RemoveDuplicate { public static void main (String args []) throws Exception { int count = 0; String line; String newLine = System.getProperty("line.seperator"); //gets line seperator for system System.out.print(" enter input file name"); // taking original file name from user Scanner scanner = new Scanner(System.in);
  • 2. String fileNameOld = scanner.next(); //reads original file name System.out.print(" enter output file name"); // takes name of new file from user String fileNameNew = scanner.next(); File file = new File (fileNameNew); // creates file object PrintWriter out = new PrintWriter (new FileWriter(file)); //creates printwriter object Scanner scanFile = new Scanner (new File(fileNameOld)); //creates scanner object for reading file int temp = 0; while(scanFile.hasNextLine()) // while numbers are in file { line = scanFile.nextLine(); // reads number int number = Integer.parseInt(line);// converts numbers to int value if(count == 0) { out.write(Integer.toString(number)); out.write(newLine); temp = number; count ++ ; //increment count } else
  • 3. { if (temp != number) { out.write(Integer.toString(number)); out.write(newLine); temp = number; } } } out.close(); // closes stream } } For reference I need to make it read an input txt/notepad file called numbers.txt which has numbers that look like following and get it to produce an output file called output.txt, which looks like the following Any help would immensly be appreciated. 12 33 33 178 239 1254 11245 x https://bb courses n x f Facebook x C Chegg Study IGuid X Hi, I Need Help Wit x C https://bb.courses.main /courses /1/1710. UMS03-C.0006 1/content/ 1873037 1/numbers.txt e.edu OM x D HMWK7 Screenshot x 5:34 PM 11/28/2016 Solution RemoveDuplicate.java import java.lang.*; import java.io.*; ///required packages import java.util.*; public class RemoveDuplicate { public static void main (String args []) throws Exception { int count = 0; String line;
  • 4. String newLine = System.getProperty("line.seperator"); //gets line seperator for system System.out.print(" enter input file name"); // taking original file name from user Scanner scanner = new Scanner(System.in); String fileNameOld = scanner.next(); //reads original file name System.out.print(" enter output file name"); // takes name of new file from user String fileNameNew = scanner.next(); File file = new File (fileNameNew); // creates file object PrintWriter out = new PrintWriter (new FileWriter(file)); //creates printwriter object Scanner scanFile = new Scanner (new File(fileNameOld)); //creates scanner object for reading file int temp = 0; while(scanFile.hasNextLine()) // while numbers are in file { line = scanFile.nextLine(); // reads number int number = Integer.parseInt(line);// converts numbers to int value if(count == 0) { out.write(Integer.toString(number)); out.write(" ");
  • 5. temp = number; count ++ ; //increment count } else { if (temp != number) { out.write(Integer.toString(number)); out.write(" "); temp = number; } } System.out.println(number); } out.close(); // closes stream } } Output: enter input file nameD: umbers.txt enter output file nameD:output.txt 2 3 4 12 33 178 239 1254 11245