SlideShare a Scribd company logo
1 of 4
Download to read offline
java programming language
The attached A12.txt file which has 2 columns with the first column being the name of the
employee and the second column holding their salary. Read the data into a 2 dimensional array
of size 1,000 rows. Once the data is inside the 2-D array print out the unsorted contents to the
screen only of the rows that are currently in-use. Sort the data using selection sort from lowest
salary to highest salary ensuring the name continues to match up with the corresponding salary.
For only the rows that are currently in-use, print the sorted array to the screen and save the sorted
data to an output file named "Sorted.txt". Turn in A12.txt, .java file, and Sorted.txt all in 1 zip
file into blackboard.
Solution
// Employee.java
import java.io.*;
import java.util.*;
import java.io.PrintWriter;
public class Employee
{
public static String[][] selectionSort(String[][] employeeDetails, int size)
{
for (int i = 0; i < size - 1; i++)
{
//System.out.println( Integer.parseInt(employeeDetails[i][1]));
int index = i;
for (int j = i + 1; j < size; j++)
if ( Integer.parseInt(employeeDetails[j][1]) < Integer.parseInt(employeeDetails[index][1]) )
index = j;
String temp = employeeDetails[index][1];
employeeDetails[index][1] = employeeDetails[i][1];
employeeDetails[i][1] = temp;
temp = employeeDetails[index][0];
employeeDetails[index][0] = employeeDetails[i][0];
employeeDetails[i][0] = temp;
}
return employeeDetails;
}
public static void main(String[] args)
{
File inputFile = new File("A12.txt");
// Check if file exists
if (!inputFile.exists())
{
System.out.println("File does not exist!");
System.exit(1);
}
String[][] employeeDetails = new String[1000][2];
int size = 0;
BufferedWriter output = null;
try(BufferedReader bf = new BufferedReader(new InputStreamReader(new
FileInputStream(inputFile))))
{
String str;
while ((str = bf.readLine()) != null)
{
String[] tokens = str.split(" ");
employeeDetails[size][0] = tokens[0];
employeeDetails[size][1] = tokens[1];
size++;
}
// output file
File file = new File("Sorted.txt");
output = new BufferedWriter(new FileWriter(file));
output.write("Employee details NametSalary ");
for (int i = 0; i < size ;i++ )
{
output.write(employeeDetails[i][0] + "t" + employeeDetails[i][1] + " ");
}
employeeDetails = selectionSort(employeeDetails,size);
output.write("  Employee details NametSalary ");
for (int i = 0; i < size ;i++ )
{
output.write(employeeDetails[i][0] + "t" + employeeDetails[i][1] + " ");
}
output.close();
}
catch (FileNotFoundException exception)
{
System.out.println("File not found.");
exception.printStackTrace();
}
catch (IOException exception)
{
System.out.println("IO error.");
exception.printStackTrace();
}
}
}
/*
A12.txt
Ayush 34531
John 2341
Eoin 345321
Sorted.txt
Employee details
Name Salary
Ayush 34531
John 2341
Eoin 345321
Employee details
Name Salary
John 2341
Ayush 34531
Eoin 345321
*/

More Related Content

Similar to java programming languageThe attached A12.txt file which has 2 col.pdf

Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notesGOKULKANNANMMECLECTC
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)Alok Kumar
 
Write a C program that implements a simple array-based insertion sort-.docx
Write a C program that implements a simple array-based insertion sort-.docxWrite a C program that implements a simple array-based insertion sort-.docx
Write a C program that implements a simple array-based insertion sort-.docxSUKHI5
 
Demonstrate your understanding of tree data structure Write a Java .pdf
Demonstrate your understanding of tree data structure Write a Java .pdfDemonstrate your understanding of tree data structure Write a Java .pdf
Demonstrate your understanding of tree data structure Write a Java .pdfRAJATCHUGH12
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streamsShahjahan Samoon
 
Please I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdfPlease I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdfasenterprisestyagi
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresArthik Daniel
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdffantoosh1
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptxNawalKishore38
 
I need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdfI need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdffonecomp
 
Discussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docxDiscussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docxedgar6wallace88877
 
Discussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docxDiscussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docxduketjoy27252
 
ONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEMONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEMRohit malav
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarROHIT JAISWAR
 
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVNOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVRohit malav
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAVRohit malav
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 

Similar to java programming languageThe attached A12.txt file which has 2 col.pdf (20)

Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
Write a C program that implements a simple array-based insertion sort-.docx
Write a C program that implements a simple array-based insertion sort-.docxWrite a C program that implements a simple array-based insertion sort-.docx
Write a C program that implements a simple array-based insertion sort-.docx
 
Demonstrate your understanding of tree data structure Write a Java .pdf
Demonstrate your understanding of tree data structure Write a Java .pdfDemonstrate your understanding of tree data structure Write a Java .pdf
Demonstrate your understanding of tree data structure Write a Java .pdf
 
Processing files sequentially in mule
Processing files sequentially in muleProcessing files sequentially in mule
Processing files sequentially in mule
 
Understanding java streams
Understanding java streamsUnderstanding java streams
Understanding java streams
 
Please I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdfPlease I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdf
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
File handling in pythan.pptx
File handling in pythan.pptxFile handling in pythan.pptx
File handling in pythan.pptx
 
I need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdfI need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdf
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Discussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docxDiscussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docx
 
Discussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docxDiscussion Board 2William Denison27 NOV 2014A Java class t.docx
Discussion Board 2William Denison27 NOV 2014A Java class t.docx
 
ONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEMONLINE STUDENT MANAGEMENT SYSTEM
ONLINE STUDENT MANAGEMENT SYSTEM
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAVNOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON 2ND PART BY ROHIT MALAV
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 

More from nitinarora01

Describe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdfDescribe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdfnitinarora01
 
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdfChapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdfnitinarora01
 
By equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdfBy equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdfnitinarora01
 
An Overview of Transport Mechanisms In Plants. Relate the structure .pdf
An Overview of Transport Mechanisms In Plants.  Relate the structure .pdfAn Overview of Transport Mechanisms In Plants.  Relate the structure .pdf
An Overview of Transport Mechanisms In Plants. Relate the structure .pdfnitinarora01
 
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdfamazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdfnitinarora01
 
All organelles (check all that apply) Are membrane bound Contain th.pdf
All organelles (check all that apply)  Are membrane bound  Contain th.pdfAll organelles (check all that apply)  Are membrane bound  Contain th.pdf
All organelles (check all that apply) Are membrane bound Contain th.pdfnitinarora01
 
A study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdfA study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdfnitinarora01
 
37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdf37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdfnitinarora01
 
Why didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdfWhy didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdfnitinarora01
 
Which property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdfWhich property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdfnitinarora01
 
Which of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdfWhich of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdfnitinarora01
 
What roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdfWhat roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdfnitinarora01
 
26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdf26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdfnitinarora01
 
What is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdfWhat is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdfnitinarora01
 
what does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdfwhat does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdfnitinarora01
 
What are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdfWhat are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdfnitinarora01
 
Weather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdfWeather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdfnitinarora01
 
The OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdfThe OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdfnitinarora01
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdfQuestion 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdfnitinarora01
 

More from nitinarora01 (20)

Describe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdfDescribe the movement of yeast cells once ingested by a paramecium &.pdf
Describe the movement of yeast cells once ingested by a paramecium &.pdf
 
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdfChapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
Chapter 2 problems.1.            (Problem 1) Of the following, whi.pdf
 
By equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdfBy equity . Party A owns a factory that emits large quantities of f.pdf
By equity . Party A owns a factory that emits large quantities of f.pdf
 
An Overview of Transport Mechanisms In Plants. Relate the structure .pdf
An Overview of Transport Mechanisms In Plants.  Relate the structure .pdfAn Overview of Transport Mechanisms In Plants.  Relate the structure .pdf
An Overview of Transport Mechanisms In Plants. Relate the structure .pdf
 
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdfamazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
amazon.com & pinterest.com -- Web 2.0 ApplicationsAddress how eac.pdf
 
All organelles (check all that apply) Are membrane bound Contain th.pdf
All organelles (check all that apply)  Are membrane bound  Contain th.pdfAll organelles (check all that apply)  Are membrane bound  Contain th.pdf
All organelles (check all that apply) Are membrane bound Contain th.pdf
 
A study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdfA study designed to evaluate the effect of the herbal remedy Echinac.pdf
A study designed to evaluate the effect of the herbal remedy Echinac.pdf
 
37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdf37. If the material below the sandstone of problem 26 is a shale with.pdf
37. If the material below the sandstone of problem 26 is a shale with.pdf
 
Why didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdfWhy didnt implementation of robots in the 1980s continue to increas.pdf
Why didnt implementation of robots in the 1980s continue to increas.pdf
 
Which property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdfWhich property of life (e.g. homeostasis) is illustrated by each of .pdf
Which property of life (e.g. homeostasis) is illustrated by each of .pdf
 
Which of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdfWhich of the following statements is FALSE regarding microbial mats.pdf
Which of the following statements is FALSE regarding microbial mats.pdf
 
What roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdfWhat roles do membranes play in a cellWhat are cell membranes com.pdf
What roles do membranes play in a cellWhat are cell membranes com.pdf
 
26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdf26. The gecko is a reptile that has the amazing ability to climb smo.pdf
26. The gecko is a reptile that has the amazing ability to climb smo.pdf
 
What is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdfWhat is soft trend vs. hard trend Analyze a specific software engin.pdf
What is soft trend vs. hard trend Analyze a specific software engin.pdf
 
what does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdfwhat does it mean to be a social scientistSolutionSocial .pdf
what does it mean to be a social scientistSolutionSocial .pdf
 
What are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdfWhat are the advantages for proteins to form three-dimensional struc.pdf
What are the advantages for proteins to form three-dimensional struc.pdf
 
Weather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdfWeather List the types of materials used to create a concrete sidewal.pdf
Weather List the types of materials used to create a concrete sidewal.pdf
 
The OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdfThe OSI Reference Model layers, in order from top to bottom, areA.pdf
The OSI Reference Model layers, in order from top to bottom, areA.pdf
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdfQuestion 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
Question 1 (1 point)Tjhe pH of blood is __________ and when the .pdf
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
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
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
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
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
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
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
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
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
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
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
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
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

java programming languageThe attached A12.txt file which has 2 col.pdf

  • 1. java programming language The attached A12.txt file which has 2 columns with the first column being the name of the employee and the second column holding their salary. Read the data into a 2 dimensional array of size 1,000 rows. Once the data is inside the 2-D array print out the unsorted contents to the screen only of the rows that are currently in-use. Sort the data using selection sort from lowest salary to highest salary ensuring the name continues to match up with the corresponding salary. For only the rows that are currently in-use, print the sorted array to the screen and save the sorted data to an output file named "Sorted.txt". Turn in A12.txt, .java file, and Sorted.txt all in 1 zip file into blackboard. Solution // Employee.java import java.io.*; import java.util.*; import java.io.PrintWriter; public class Employee { public static String[][] selectionSort(String[][] employeeDetails, int size) { for (int i = 0; i < size - 1; i++) { //System.out.println( Integer.parseInt(employeeDetails[i][1])); int index = i; for (int j = i + 1; j < size; j++) if ( Integer.parseInt(employeeDetails[j][1]) < Integer.parseInt(employeeDetails[index][1]) ) index = j; String temp = employeeDetails[index][1]; employeeDetails[index][1] = employeeDetails[i][1]; employeeDetails[i][1] = temp; temp = employeeDetails[index][0]; employeeDetails[index][0] = employeeDetails[i][0]; employeeDetails[i][0] = temp;
  • 2. } return employeeDetails; } public static void main(String[] args) { File inputFile = new File("A12.txt"); // Check if file exists if (!inputFile.exists()) { System.out.println("File does not exist!"); System.exit(1); } String[][] employeeDetails = new String[1000][2]; int size = 0; BufferedWriter output = null; try(BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)))) { String str; while ((str = bf.readLine()) != null) { String[] tokens = str.split(" "); employeeDetails[size][0] = tokens[0]; employeeDetails[size][1] = tokens[1]; size++; } // output file File file = new File("Sorted.txt"); output = new BufferedWriter(new FileWriter(file)); output.write("Employee details NametSalary "); for (int i = 0; i < size ;i++ ) { output.write(employeeDetails[i][0] + "t" + employeeDetails[i][1] + " "); } employeeDetails = selectionSort(employeeDetails,size);
  • 3. output.write(" Employee details NametSalary "); for (int i = 0; i < size ;i++ ) { output.write(employeeDetails[i][0] + "t" + employeeDetails[i][1] + " "); } output.close(); } catch (FileNotFoundException exception) { System.out.println("File not found."); exception.printStackTrace(); } catch (IOException exception) { System.out.println("IO error."); exception.printStackTrace(); } } } /* A12.txt Ayush 34531 John 2341 Eoin 345321 Sorted.txt Employee details Name Salary Ayush 34531 John 2341 Eoin 345321 Employee details Name Salary John 2341