Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2007, 05:15 AM
Member
 
Join Date: Dec 2007
Posts: 1
BSOS is on a distinguished road
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.
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-11-2007, 06:54 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
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];
Your problem is here: int f = (String) 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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to scan your computer for ports in use Java Tip java.net 0 04-07-2008 10:13 PM
How to execute an External Program through Java program Java Tip java.io 0 04-04-2008 04:40 PM
which are the final classes in the java APi vagarwal_mca New To Java 2 01-10-2008 04:47 AM
JAVA software solutions:For AP Comp. Science (Lewis,Loftus,Cocking) padutch New To Java 4 11-28-2007 01:59 AM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 11:33 PM


All times are GMT +3. The time now is 04:39 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org