Results 1 to 5 of 5
  1. #1
    leapinlizard is offline Member
    Join Date
    Apr 2009
    Posts
    19
    Rep Power
    0

    Default Build Instances problem

    Java Code:
    public class BookTest
    {
    	public static void main(String args[])
    
    	{
    
                   Book bookArray[] = new Book[6]; 
                    
    	 	String dataArray [][] = {{"Java","john","123","Wiley","London","25.50","Book"},
    					 {"Where's my car", "Aston Kutcher","777","ORiely","New York","5.95","Fiction","1234","king"},
    					 {"Earthquakes","ChuckBerry","435","LABooks","LA","75.00","NonFiction"},
    					 {"C++","Jones","456","Random","NY","10.75","Book"},
    					 {"Doom","The Rock","918","Sans Publishing","LA","12.50","Fiction","32342","Queen"}, 
    					 {"Universal Studios","Walt","987","Dell","Houston","29.90","NonFiction"}};
    	
                    for (int i=0; i<bookArray.length; i++)
                    {
                    	
    			  bookArray[i]=new Fiction(dataArray[i][0],dataArray[i][1],                    Integer.parseInt(dataArray[i][2]), new Publisher(dataArray[i][3],dataArray[i][4]), Double.parseDouble(dataArray[i][5]), Integer.parseInt(dataArray[i][6]), new Background(dataArray[i][7], dataArray[i][8]));
    
                              bookArray[i]= new NonFiction(dataArray[i][0],dataArray[i][1], Integer.parseInt(dataArray[i][2]), new Publisher(dataArray[i][3],dataArray[i][4]), Double.parseDouble(dataArray[i][5]),"History");
                                                     
    
    		}// end of I for Loop
    
    
    
    ///// 
    
    public class Fiction extends Book 
    {
    
       private int code; 
       private double totalCharge =0.0;
       private Background background;
    
    
      public Fiction(String t, String a, int i, Publisher pub, double p, int cd, Background b)
       {
    	super(t,a,i,pub,p);
    	setCode(cd);
    	setBackground(b);
       }
    
    
    Background file has two attributes
    and they both are string types
    
    My question is what i'm doing wrong 
    
    i want to build instance for FICTION please help me correct this error, also this is not a complete code it's really big so I just post only the main part where i'm getting error when i'm making instance for Fiction file.
    thanks

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    what are the errors?
    Last edited by mtyoung; 04-21-2009 at 10:35 AM.

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    dataArray is String[6][7]

    so what can dataArray[i][7], dataArray[i][8] be?

  4. #4
    leapinlizard is offline Member
    Join Date
    Apr 2009
    Posts
    19
    Rep Power
    0

    Default

    Error:

    Exception in thread "main" java.lang.NumberFormatException: for input string "Book"
    at java.lang.NumberFormatException.forInputString(unk nown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at BookTest.main(BookTest.java:23)

  5. #5
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

Similar Threads

  1. Array of instances using Math.random()
    By xgi1008 in forum New To Java
    Replies: 16
    Last Post: 01-26-2011, 12:10 AM
  2. [SOLVED] SVN project's build path problem
    By er_zhong in forum Eclipse
    Replies: 0
    Last Post: 04-14-2009, 05:03 PM
  3. Calling a method for all instances of an object
    By rattle in forum New To Java
    Replies: 4
    Last Post: 04-30-2008, 03:10 PM
  4. Object Reflection: Creating new instances
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 09:13 PM
  5. Naming object instances
    By oldgit in forum New To Java
    Replies: 9
    Last Post: 02-08-2008, 12:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •