Question: Code is in Java. I have the assignment described below, as well as the code I have that is close to working. I get all

Code is in Java. I have the assignment described below, as well as the code I have that is close to working. I get all the values and assign double values to them. I need to create a sort function that sorts the doubles in order. The end goal is to write the sorted arraylist into an output file. All natural numbers are sorted in descending (unless there's 666 then its ascending) and all strings are sorted according to the rubric. DO NOT IMPORT ANY JAVA.UTIL instead, create a class TArrayList that has add, contains, removes and length functions.

Assignment Description

If there is an input in the input file that is not a natural number or one of the symbols below, output Input Error and terminate.

This is the method as to how the input file is to be sorted to create an output file.

  • 0 < Do < 1
  • 100 < Re < 101
  • 1000 < Mi < 1001
  • 3 < & < 4
  • 3 < @ < &
  • 1005000 < % < 1005001
  • 55 < Asymbolwithareallylongname < 56
  • 20 < $ < 21
  • 15 < Fa < 16
  • 103 < One < 104
  • One < Three < 104
  • One < Two < Three

If the given list contains any number of 666, then the result list should be sorted in ascending order, without any occurences of 666, but with one @ added (even if the list already contains @s).

The output file is similar to the input file in that it is one element per line, with no blank lines.

Code So Far (Create an class TArrayList that has add, contains, length, and removes functions) (Complete sortList function that sorts the double values,)

import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException;

public class Sorting {

public Sorting() { } public static void main(String[] args) throws IOException { // String inputFile = args[0]; File file = new File("input.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String validInput = "Do Re Mi & @ % Asymbolwithareallylongname $ Fa One Two Three 0"; String text; TArrayList list = new TArrayList(); boolean is666Exist = false; String order = "descending"; // String output = args[1]; File outputFile = new File("filename.txt"); outputFile.createNewFile(); FileWriter writer = new FileWriter(outputFile); for(int i=0; i

} public static void sortList (String order) { //order the doubles a. } private double getValue(String o1) {

//orders the input into doubles that relate to the order structure in assignment description double a = 0, b=0; if(o1.equals("Do")) { a = 0.5; } else if (o1.equals("0")) { a = 0.0; } else if(o1.equals("Re")) { a = 100.5; } else if(o1.equals("Mi")) { a = 1000.5; } else if(o1.equals("&")) { a = 3.5; } else if(o1.equals("@")) { a = 3.25; } else if(o1.equals("%")) { a = 1005000.5; } else if(o1.equals("Asymbolwithareallylongname")) { a = 55.5; } else if(o1.equals("$")) { a = 20.5; } else if(o1.equals("Fa")) { a = 15.5; } else if(o1.equals("One")) { a = 103.3; } else if(o1.equals("Two")) { a = 103.5; } else if(o1.equals("Three")) { a = 103.7; } else { a = Double.parseDouble(o1); } return a; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!