Spartan 051
Well-Known Member
Ive been writing this for a java class and ive ran into a little snag.
Ive been stupid at the last step of the assignment which is:
So any suggestions would be greatly appreciated
<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-spacere;overflow:auto'>
import java.io.*;
import java.text.*;
public class GellersonPrefab{
//**********************************************
// The Class that compiles and runs the program
//**********************************************
String department, supplier;
Double sale;
String companyList[] = new String[200];
String departmentList[]= new String[4];
int companyFound = 0;
int departmentFound = 0;
double departmentArray[][] = new double[200][4];
// double departmentArrayTotal[][] = new double[2][4];
public static void main (String args[])
{(new GellersonPrefab()).printReport();}
private void printReport()
{
//***************************************
// Prints the MISC.text files and the header
// and column headings
//***************************************
DecimalFormat formatDecimal = new DecimalFormat("0.00");
System.out.println(String.format("\n"+"%60s", "Gellerson Prefab"+"\n"));
System.out.println(String.format("%5s%-32s%-15s%-15s%-15s%9s%12s\n",
"","SUPPLIER", "Systems","Roofing","Furnishing","Structure","SALES"));
try
{
BufferedReader readDataFile = new BufferedReader(new FileReader("/Users/MISC.txt"));
String dataFromFile;
while((dataFromFile = readDataFile.readLine()) != null)
{
processSupplier(dataFromFile);
}
readDataFile.close();
} // end try
catch (IOException e)
{
System.err.print("error " + e);
}// End catch
//****************************************
// Creates the 2d array called departmentArray
// and prints out the departments
//******************************************
for( int departmentRow= 0; departmentRow<companyFound; departmentRow++)
{
double departmentTotal = 0;
System.out.print(companyList[departmentRow]);
for (int departmentCol = 0; departmentCol<4; departmentCol++)
{
departmentTotal += departmentArray [departmentRow][departmentCol];
System.out.printf("%15.2f",( departmentArray [departmentRow][departmentCol]));
}// end for loop
System.out.printf("%15s",formatDecimal.format(departmentTotal)+ "\n");
}// end for loop
System.out.println();
}// End printReport method
private void processSupplier (String readData)
{
//****************************************
// Reads the MISC.test file and creates companyLocation and
// departmentLocation integers. It also compiles sales
//****************************************
supplier = readData.substring(0,30);
department = readData.substring(30,40);
sale = Double.parseDouble(readData.substring(40,47));
int companyLocation = linearSearch (companyList, supplier, companyFound);
int departmentLocation = linearSearch (departmentList, department, departmentFound);
departmentArray[companyLocation][departmentLocation]+=sale;
//******************************************
// Two if statements that compile companies and departments
//******************************************
if(companyFound == companyLocation)
{
companyList[companyFound] = supplier;
companyFound++;
} // end if
if(departmentFound == departmentLocation)
{
departmentList[departmentFound] = department;
departmentFound++;
}// end if
} //end method processSupplier
static int linearSearch (String [] list, String search, int listLength)
// *****************************************************************
// This method looks for search in the list which currently has
// listLength elements. If fournd, the position in list is returned.
// If not, listLength is returned.
// *****************************************************************
{
int position = 0;
while (position < listLength && !list[position].equals(search))
position++;
return position;
} // end search
}</div>
Compiled code:
Ive been stupid at the last step of the assignment which is:
At the bottom of the report, give the total of all the numbers in each
numeric column and give the maximum value found in each numeric
column.
So any suggestions would be greatly appreciated
<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-spacere;overflow:auto'>
import java.io.*;
import java.text.*;
public class GellersonPrefab{
//**********************************************
// The Class that compiles and runs the program
//**********************************************
String department, supplier;
Double sale;
String companyList[] = new String[200];
String departmentList[]= new String[4];
int companyFound = 0;
int departmentFound = 0;
double departmentArray[][] = new double[200][4];
// double departmentArrayTotal[][] = new double[2][4];
public static void main (String args[])
{(new GellersonPrefab()).printReport();}
private void printReport()
{
//***************************************
// Prints the MISC.text files and the header
// and column headings
//***************************************
DecimalFormat formatDecimal = new DecimalFormat("0.00");
System.out.println(String.format("\n"+"%60s", "Gellerson Prefab"+"\n"));
System.out.println(String.format("%5s%-32s%-15s%-15s%-15s%9s%12s\n",
"","SUPPLIER", "Systems","Roofing","Furnishing","Structure","SALES"));
try
{
BufferedReader readDataFile = new BufferedReader(new FileReader("/Users/MISC.txt"));
String dataFromFile;
while((dataFromFile = readDataFile.readLine()) != null)
{
processSupplier(dataFromFile);
}
readDataFile.close();
} // end try
catch (IOException e)
{
System.err.print("error " + e);
}// End catch
//****************************************
// Creates the 2d array called departmentArray
// and prints out the departments
//******************************************
for( int departmentRow= 0; departmentRow<companyFound; departmentRow++)
{
double departmentTotal = 0;
System.out.print(companyList[departmentRow]);
for (int departmentCol = 0; departmentCol<4; departmentCol++)
{
departmentTotal += departmentArray [departmentRow][departmentCol];
System.out.printf("%15.2f",( departmentArray [departmentRow][departmentCol]));
}// end for loop
System.out.printf("%15s",formatDecimal.format(departmentTotal)+ "\n");
}// end for loop
System.out.println();
}// End printReport method
private void processSupplier (String readData)
{
//****************************************
// Reads the MISC.test file and creates companyLocation and
// departmentLocation integers. It also compiles sales
//****************************************
supplier = readData.substring(0,30);
department = readData.substring(30,40);
sale = Double.parseDouble(readData.substring(40,47));
int companyLocation = linearSearch (companyList, supplier, companyFound);
int departmentLocation = linearSearch (departmentList, department, departmentFound);
departmentArray[companyLocation][departmentLocation]+=sale;
//******************************************
// Two if statements that compile companies and departments
//******************************************
if(companyFound == companyLocation)
{
companyList[companyFound] = supplier;
companyFound++;
} // end if
if(departmentFound == departmentLocation)
{
departmentList[departmentFound] = department;
departmentFound++;
}// end if
} //end method processSupplier
static int linearSearch (String [] list, String search, int listLength)
// *****************************************************************
// This method looks for search in the list which currently has
// listLength elements. If fournd, the position in list is returned.
// If not, listLength is returned.
// *****************************************************************
{
int position = 0;
while (position < listLength && !list[position].equals(search))
position++;
return position;
} // end search
}</div>
Compiled code:
Last edited by a moderator: