Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is written in Java. Can you please change the coding to do the exact same thing but with different methods. The code just needs

This is written in Java. Can you please change the coding to do the exact same thing but with different methods. The code just needs rewritten but have the same results. That was the only instruction I was given!

public class Storm {

DataSet data; Scanner input; //get the folder name void begin(){ System.out.print("Enter data folder name: "); //Scanner for input @SuppressWarnings("resource") Scanner input = new Scanner(System.in); String filename = input.nextLine();

if(filename.charAt(filename.length()-1) == '/') filename = filename.substring(0, filename.length()-1); data = new DataSet(10); //read contents of file try{ FileInputStream folder = new FileInputStream(filename); int i = 0; while((i=folder.read())!=-1) { System.out.println((char)i); } folder.close();

//File not available catch } catch(Exception e){ System.out.println("File is not availible"); System.exit(1); }

//data = new DataSet(10); //data = InputReader.process(filename, data); }

//get user entry for what to do next boolean loop(){ System.out.print("Enter (o) output, (sum) summary, (f) find, or (q) quit: "); String choice = input.nextLine(); //check each option for user entry and get next input //output if(choice.equals("o")){ //Get output file name System.out.print("Enter output file name: "); choice = input.nextLine(); //if file null //**************************************************************************************// OutputStream os = null; if(choice.equals("")){ os = System.out; } else{ try { os = new FileOutputStream(new File(choice)); } catch (IOException e){ System.out.println("File is not availible."); os = System.out; } } for(int i=0; i 9999){ System.out.println("Invalid year. Returning to loop."); return true; }

Integer[] vals = new Integer[4]; for(int i=0; i<4; i++) vals[i] = 0;

Double[] cost = new Double[2]; for(int i=0; i<2; i++) cost[i] = 0.0; for(int i=0; i

} } for(int ii=4; ii<6; ii++){ if(summ[ii].length() == 0 || summ[ii].equals(0)) continue; Integer modif = 0; if(summ[ii].charAt(summ[ii].length()-1) == 'K'){ modif = 1000; } else { modif = 1000*1000; }

String change = new String(summ[ii]); change = change.substring(0, change.length()-1); try{ cost[ii-4] += Double.parseDouble(change) * (double) modif; } catch (Exception e){ continue; } } } }

System.out.printf("Year: %d; total INJURIES_DIRECT:%d; total INJURIES_INDIRECT: %d; total DEATHS_DIRECT: %d; total DEATHS_INDIRECT: %d; total DAMAGE_PROPERTY: %fK; total DAMAGE_CROPS: %fK. ", year, vals[0], vals[1], vals[2], vals[3], cost[0]/1000, cost[1]/1000); } //find else if(choice.equals("f")){ System.out.println("Enter search field (0-10): "); Integer index = input.nextInt(); //String dummy = userEntry.nextLine();

if(0 > index || index > 10){ return true; } System.out.println("Enter field value: "); String search = input.nextLine();

Integer counter = 0; for(int i=0; i

public static void main(String[] args){ Storm app = new Storm();

app.begin(); while(app.loop()){

} System.out.println("Quitting..."); } }

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_2

Step: 3

blur-text-image_3

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions