Results 1 to 2 of 2
- 12-11-2007, 04:15 AM #1
Member
- Join Date
- Dec 2007
- Posts
- 1
- Rep Power
- 0
Help On Computer Science Final!!!! Java Program Help!!!!
I need this program to compile with out any errors or warnings. Any help would be dearly appreciated.
Java Code:import java.util.*; import java.io.*; /** * A class that represents a class score book. This * book maps names to scores and grades. This will * read the names, scores and grade information from a file. */ public class CourseData2 { /////////////////// fields /////////////////// private String fileName; private Map phoneMap = new HashMap(); /////////////////// constructors /////////////////// /** * Constructor that takes a file name and reads * in the names and phone numbers from a file. * @param file the name of the file to read */ public CourseData2(String file) { this.fileName = file; // Read the map information in form the file readInfoFromFile(); } // constructor /////////////////// methods /////////////////// /** * Get the phone number for hte passed nam * @param name the name to look up in hte map * @return the phone number if found, else null */ public String getPhoneNumber(String name) { String phoneNumber = (String) phoneMap.get(name); return phoneNumber; } // method getPhoneNumber() /** * Method to read the phone information from a * file and use it to fill hte map */ public void readInfoFromFile() { String line = null; String[] phoneArray = null; try { // create the reader BufferedReader reader = new BufferedReader(new FileReader(fileName)); // loop reading from the file while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) { if (line.indexOf(":") >= 0) { phoneArray = line.split(":"); int f = (String)phoneArray[2]; if (0 <= f <= 100) { String a = null; if (0 <= f < 60) { a = "E";} else if (60 <= f < 70) { a = "D";} else if (70 <= f < 80) { a = "C";} else if (80 <= f < 90) { a = "B";} else if (90 <= f <= 100) { a = "A";} } else if ( ((int)f > 100) + ((int)f < 0) ) { SimpleOutput.showError("Score is not an integer"); String g = new String(); g = phoneArray[2]; }//if < 0 }//while 2 phoneMap.put(phoneArray[0].trim(), (phoneArray[1].trim() + phoneArray[2].trim() + a.trim())); } // if } // while /*if (f < 60) { (String)f = "E";} else if (60 <= f < 70) { (String)f = "D";} else if (70 <= f < 80) { (String)f = "C";} else if (70 <= f < 90) { (String)f = "B";} else if (90 <= f) { (String)a = "A";}*/ // Close the reader reader.close(); } // try catch (FileNotFoundException ex) { SimpleOutput.showError("Could not find the file \"" + fileName + "\"."); } // catch catch (Exception ex) { ex.printStackTrace(); } // catch } // method readInfoFromFile() public void printBook() { // Sort hashtable. Vector phoneVector = new Vector(phoneMap.keySet()); Collections.sort(phoneVector); // Display (sorted) hashtable. for (Enumeration phoneEnumeration = phoneVector.elements(); phoneEnumeration.hasMoreElements();) { String key = (String)phoneEnumeration.nextElement(); System.out.println("Name: " + key + ", Year: " + phoneMap.get(key) + ", Score: " + phoneMap.get(key) + ", Grade: " + phoneMap.get(key)); } // for } // method printBook() /* main method for testing */ public static void main(String[] args) { CourseData2 phoneBook = new CourseData2("scores12.txt"); System.out.println(phoneBook.getPhoneNumber("Lee")); System.out.println(phoneBook.getPhoneNumber("Smith")); phoneBook.printBook(); } // main() } // class
- 12-11-2007, 05:54 AM #2
Senior Member
- Join Date
- Nov 2007
- Location
- Newport, WA
- Posts
- 141
- Rep Power
- 0
Java Code:int f = (String) phoneArray[2]; if (0 <= f <= 100) { String a = null; if (0 <= f < 60) { a = "E"; } else if (60 <= f < 70) { a = "D"; } else if (70 <= f < 80) { a = "C"; } else if (80 <= f < 90) { a = "B"; } else if (90 <= f <= 100) { a = "A"; } } else if (((int) f > 100) + ((int) f < 0)) { SimpleOutput.showError("Score is not an integer"); String g = new String(); g = phoneArray[2];
Try compiling it and seeing the error for yourself. I surely hope none actually takes this post seriously and does your homework for you.
Similar Threads
-
How to scan your computer for ports in use
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 09:13 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 03:40 PM -
which are the final classes in the java APi
By vagarwal_mca in forum New To JavaReplies: 2Last Post: 01-10-2008, 03:47 AM -
JAVA software solutions:For AP Comp. Science (Lewis,Loftus,Cocking)
By padutch in forum New To JavaReplies: 4Last Post: 11-28-2007, 12:59 AM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 10:33 PM
Bookmarks