/********************************** * Assignment 1 * Date: 6-26-2006 * Bryant Yung **********************************/ import java.math.*; import java.io.*; import java.util.*; public class Orders { protected String[] months=new String[12]; protected double[] monarray=new double[12]; protected double total; private String monmax, monmin; private String file = null, line; /********************************** * Constructor * Sets filepath * Assigns Each Month String to Months Array **********************************/ public Orders() { file="Orders.csv"; months[0]="Jan"; months[1]="Feb"; months[2]="Mar"; months[3]="Apr"; months[4]="May"; months[5]="Jun"; months[6]="Jul"; months[7]="Aug"; months[8]="Sep"; months[9]="Oct"; months[10]="Nov"; months[11]="Dec"; } // end of constructor /********************************** * Process * Reads into file * Adds Freight values according to months in year 97 and stores in array monarray * Assigns Total Value of all Freight for year 97 **********************************/ public void Process() throws IOException { double freight; int date; String reqyear="97"; String[] columninfo=new String[14]; String[] dateinfo=new String[3]; BufferedReader buf=null; buf=new BufferedReader(new FileReader(file)); String line=buf.readLine(); String nextline=buf.readLine(); while(nextline != null) { line=nextline; nextline=buf.readLine(); columninfo=line.split(","); dateinfo=columninfo[3].split("-"); String year=new String(dateinfo[2]); if(year.compareTo(reqyear)==0) { // to see if order in year 97 date=findmonth(dateinfo[1]); String freightcheck=new String(columninfo[7]); char[] valuecheck=freightcheck.toCharArray(); Character quotation=new Character('\"'); if(quotation.compareTo(valuecheck[0])==0) { // checks if value is over 999.99, and String value=columninfo[7]+columninfo[8];// a quotation is used String[] solvedvalue=new String[3]; // if so solves for correct freight value solvedvalue=value.split("\""); freight=Double.parseDouble(solvedvalue[1]); // parse string to double } // end of if else { freight=Double.parseDouble(columninfo[7]); // parse string to double } // end of else for(int x=0; x<12; x++) { if(x==date) { this.monarray[x]=this.monarray[x]+freight; // adds freight according to month } // end if }// end for loop } // end if } // end while loop buf.close(); monarray=rounder(monarray); // rounds values to two decimals. total=total(monarray);// assigns total, total value of all freight } // end Process /********************************** * getmonthinfo * getter method to get the monarray arary * which holds information for freight total per month **********************************/ public double[] getmonthinfo() { return this.monarray; } // end of getmonthinfo /********************************** * setorderfile * Sets file path to the string which is input **********************************/ public void setorderfile(String s) { this.file=s; } // end of setorderfile /********************************** * MonMax * determines the Month with Maximum value of Freight **********************************/ public String MonMax() { double max=0; int month=0; for(int x=0; x<12; x++) { if(monarray[x] > max) { max=monarray[x]; month=x; } // end if } // end for loop monmax=this.months[month]; return monmax; } // end Monmax /********************************** * MonMin * Determines the month with minimum value of Freight **********************************/ public String MonMin() { double min=monarray[0]; int month=0; for(int x=1; x<12; x++) { if(monarray[x] < min) { min=monarray[x]; month=x; } // end if } // end for loop monmin=this.months[month]; return monmin; }// end monmin /********************************** * findmonth * returns the int associated with the name of the month **********************************/ private int findmonth(String date) { int number=1; String year=new String(date); for(int x=0; x<12; x++) { if(year.compareTo(months[x])==0) { //if(date==months[x]) { number=x; x=12; } // end if } // end for loop return number; } // end findmonth /********************************** * rounder * method which takes in array of unrounded values * and output array of rounded values to two decimals **********************************/ private double[] rounder(double[] array) { for(int x=0; x