Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this code that functions perfectly as per the assignment outline, however I was just notified that I cannot import java.util for array list

I have this code that functions perfectly as per the assignment outline, however I was just notified that I cannot import java.util for array list or list. How do I change my code to satisfy these new issues? Creating a new class and implementing ArrayList seems like a possible way.

Code that works but have to change so it does not import java.util.

package Working;

import java.io.*; import java.util.ArrayList; import java.util.List; class rubric2 { public static void main(String args[]) throws IOException { List list=new ArrayList();

String a[] = {"Do","Re","Mi","&","@","%","Asymbolwithareallylongname","$","Fa","One","Three","Two"};

double av[] = {0.5,100.5,1000.5,3.5,3.25,1005000.5,55.5,20.5,15.5,103.25,103.75,103.5}; FileWriter pw = new FileWriter("output2.txt");

for(int i=0;i

BufferedReader br = new BufferedReader(new FileReader("input2.txt")); String line = br.readLine(); double val[] = new double[10000]; int c=0;

List si=new ArrayList();

boolean sortDesc = true; List check=new ArrayList(); String nat[] = {"0","1","2","3","4","5","6","7","8","9"}; for(int i=0;i

while(line!=null) { try { String s = line; if(s.equals("666")) sortDesc = false; if(list.contains(s)) { int in = list.indexOf(s); val[c] = av[in]; si.add(c); c++; } else { for(int i=0;i

if(sortDesc == true) si = sortdesc(val,c,si); else si = sortasc(val,c,si);

for(int i=0;i

@SuppressWarnings("deprecation") static List sortasc(double arr[],int n,List si) { for (int i = 0; i < n-1; i++) {

int min_idx = i; for (int j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; if(si.contains(new Integer(min_idx))) { if(!si.contains(new Integer(i))) { si.remove(new Integer(min_idx)); si.add(i); } } else if(si.contains(new Integer(i))&&!si.contains(new Integer(min_idx))) { si.remove(new Integer(i)); si.add(min_idx); } double temp = arr[min_idx]; arr[min_idx] = arr[i]; arr[i] = temp; } return(si); }

static List sortdesc(double arr[],int n,List si) {

for (int i = 0; i < n-1; i++) {

int min_idx = i; for (int j = i+1; j < n; j++) if (arr[j] > arr[min_idx]) min_idx = j; if(si.contains(new Integer(min_idx))) { if(!si.contains(new Integer(i))) { si.remove(new Integer(min_idx)); si.add(i); } } else if(si.contains(new Integer(i))&&!si.contains(new Integer(min_idx))) { si.remove(new Integer(i)); si.add(min_idx); } double temp = arr[min_idx]; arr[min_idx] = arr[i]; arr[i] = temp; } return(si); }

static int index(double a[], double v) { for(int i=0;i

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions