10 Replies - 853 Views - Last Post: 30 May 2011 - 02:55 PM Rate Topic: -----

#1 MissZuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Adding a subclass and getting the Output

Posted 29 May 2011 - 06:15 PM

I was hoping not to have to open a new topic on this but I am at a loss.

I need to create a subclass (which I think I did right) that add a feature to the cameras class and also have to add a 5% restocking fee to the cameras. I believe I have set the subclass up correctly but cannot figure out how to get it to out print. This is the only forum where I feel like you all really help so I am asking for help again please.

Inventory class:
// Inventory.java
// Inventory class

public class Inventory {
	
	// main begins execution of program
    public static void main( String args [] )
    {
    	
    	// display message
        System.out.println( "Welcome to Camera Inventory" );
    	
        // create array
        Cameras[] Cams = new Cameras[5] ;
        
        Cams[0] = new Cameras("Nikon COOLPIX S4100 Value Bundle","Photo Electronics Department", 1, 14, 179.00);
        Cams[1] = new Cameras("Kodak EasyShare PlayFull Blue-Silver HD Video Camera","Video Electronicss Department", 2, 10, 149.00);
        Cams[2] = new Cameras("Flip UltraHD U260 Black Video Camera","Video Electronics Department", 3, 7, 99.00);
        Cams[3] = new Cameras("Olympus Stylus 5010 Titanium  Digital Camera","Photo Electronics Department", 4, 12, 87.54);
        Cams[4] = new Cameras("Kodak Easyshare M580 Pink Digital Camera","Photo Electronics Department", 5, 13, 99.88);
        
        // sorter for arrays
        bubbleSort( Cams );
        
        double total = 0;
        for( int count = 0; count< Cams.length; count++ )
        {
        	total += Cams[count].getCamerasStock();
        	
            // show inventory information 
            System.out.println();
            System.out.printf( "Cameras %d:\n", count + 1 );
    		System.out.printf( "%s %s\n", "Camera Name:",Cams[count].getCamerasName() );
            System.out.printf( "%s %s\n","Camera Department:",Cams[count].getCamerasDepartment() );
            System.out.printf( "%s %d\n","Camera Item Number:",Cams[count].getCamerasItem() );
            System.out.printf( "%s %d\n", "Camera Stock:", Cams[count].getCamerasStock() );
            System.out.printf( "%s $%.2f\n", "Camera Price:", Cams[count].getCamerasPrice() );
            System.out.printf( "%s $%.2f\n", "Total Cameras Inventory:", Cams[count].getCamerasValue() );
            System.out.println();
        } //end for loop
        

        {
        double totalValue = 0;	
        for(int count = 0; count < Cams.length ; count++ )
			totalValue += Cams[count].getCamerasValue();
        {
        	System.out.printf( "%s $%.2f ", "Total Inventory Value:", totalValue );
        }
                
      } 
        
    } //end main method


	private static void bubbleSort(Cameras[] cams) 
	{
		boolean swapped = true;
		int j = 0;
		Cameras tmp;
		while( swapped)
		{
			swapped = false;
			j++;
			for ( int i = 0; i < cams.length - j; i++)
			{
				if( cams[i].getCamerasName().codePointAt(0) > cams[ i + 1].getCamerasName().charAt(0) )
				{
					tmp = cams[i];
					cams[i] = cams[i + 1];
					cams[i + 1]=tmp;
					swapped = true;
				}
			}
			
		}
	}
           
} // end Inventory class





Cameras class:
// Cameras.java
// Cameras class

public class Cameras {


    private String camerasName, camerasDepartment; // name of camera and department name
    private int camerasItem, camerasStock; // item number and amount in stock
    private double camerasPrice; // price of cameras
    
    // five-argument constructor
    Cameras( String name, String department, int item, int stock, double price )
    { 
         camerasName = name;
         camerasDepartment = department;
         camerasItem = item;
         camerasStock = stock;
         camerasPrice = price;
    } // end five-argument constructor
    
    // set and get for each method
    // camera name
    public void setCamerasName( String name )
    {
        camerasName = name;
    }
    
    public String getCamerasName()
    {
        return camerasName;
    } // end camera name
    
    // camera department
    public void setCamerasDepartment( String department )
    {
        camerasDepartment = department;
    }
    
    public String getCamerasDepartment()
    {
        return camerasDepartment;
    } //end camera department
    
    // camera item
    public void setCamerasItem( int item)
    {
        camerasItem = item;
    }
    
    public int getCamerasItem()
    {
        return camerasItem;
    } // end camera item
    
    // camera stock
    public void setCamerasStock( int stock)
    {
        camerasStock = stock;
    }
    
    public int getCamerasStock()
    {
        return camerasStock;
    } // end camera stock
    
    public void setCamerasPrice( double price )
    {
        camerasPrice = price;
    }
    
    public double getCamerasPrice()
    {
        return camerasPrice;
    } // end camera price and set/get 
    
    // calculate cameras stock value
    public double getCamerasValue()
    {
    	return camerasPrice * camerasStock;
    }
    	
	public int compareTo(Cameras cameras) 
	{
		return 0;
	}


   // display inventory
    public void showInventory()
    {
         System.out.println(); // outputs blank line

         System.out.println( "Cameras Name:  "+camerasName );
         System.out.println( "Cameras Department:  "+camerasDepartment );
         System.out.println( "Cameras Item Number:  "+camerasItem );
         System.out.println( "Cameras Stock:  "+camerasStock );
         System.out.printf( "Cameras Price:  $%.2f", camerasPrice );

         DigitalCameras DigCam = new DigitalCameras
              ( "Nikon COOLPIX S4100 Value Bundle","Photo Electronics Department", 1, 14, 179.00, 0 );    
         
         System.out.println( "%.2f\n Resolution in MegaPixels:  "+DigCam.getMegaPixels() );
                         
 
   } // end display inventory
	


}



Extended Cameras class:
// DigitalCameras.java
// Extends Cameras class

public class DigitalCameras extends Cameras 
{
	private double megaPixels;
	int restock;
	private int restockFee;
	
	    public DigitalCameras(String name, String department, int item, int stock,
			double price, double mp ) 
	    {
			super(name, department, item, stock, price);		    
	    } 
	    
	    public void setMegaPixels(double mp)
	    {
	    	megaPixels = mp;
	    }
	    
	    public double getMegaPixels() 
	    {
	    	return megaPixels;
	    }
	 
	    // calculate re-stock fee
	    public void setRestock(double restock)
	    {
	    	restock = getCamerasPrice() * .05;	
	    }
	    
        public double getRestock()
        {
    	return restock;  
        }	

        public void setRestockFee ( double value)
        {
        	restockFee = (int) (this.getRestock() + this.getCamerasPrice() );
        }
        
        public double getRestockFee()
        {
    	  return restockFee;
        }
        public String toString()
        {
        	 String formatString = "Manufacturer:  %s";
             formatString += "Restocking Fee:  $%.2f";
             formatString = String.format( formatString, megaPixels,
                  super.getCamerasPrice() * 0.05 );
             return( formatString + super.toString() );
        }
        
     // display inventory
        public void showInventory()
        {
             super.showInventory();
             System.out.println( toString() );

             // Display value plus re-stock fee
             System.out.printf( "\nInventory value of "+getCamerasName()+ " is = $%.2f\n",
                  getRestockFee() );     

        } // end method display inventory


} // Digital Cameras class



I am not getting any errors so far just need to figure out how to get the resolutions (MegaPixels) and restock fee to output.

Is This A Good Question/Topic? 0
  • +

Replies To: Adding a subclass and getting the Output

#2 Renagado  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 388
  • Joined: 14-June 09

Re: Adding a subclass and getting the Output

Posted 29 May 2011 - 06:26 PM

One approach would be to test if the Cameras is a DigitalCameras.(single form is more appropriate for a class name btw). So say you have an array of Cameras and DigitalCameras mixed together you could do for example:


if(cameraList[i] instanceof DigitalCameras)//check if its a DigitalCameras
{
Camera c = (DigitalCameras)cameraList[i];//cast it to a DigitalCameras
c.getMegaPixels();//do things only digital cameras can do!
}

Is this what you wanted to know?
Was This Post Helpful? 1
  • +
  • -

#3 MissZuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Re: Adding a subclass and getting the Output

Posted 29 May 2011 - 06:34 PM

All cameras today are digital so I used video cameras and photo cameras. I figure I would use the resolution just on the photo cameras. I am not allowed to use an array list in this (not sure why but can't :dontgetit: )

Main thing I am wondering is if I set the classes up correctly and how to get the information ( restock fee and resolution) to show up in each of my cameras information as needed.

Example of output now:
Cameras 5:
Camera Name: Olympus Stylus 5010 Titanium  Digital Camera
Camera Department: Photo Electronics Department
Camera Item Number: 4
Camera Stock: 12
Camera Price: $87.54
Total Cameras Inventory: $1050.48


and what I am trying to achieve:
Cameras 5:
Camera Name: Olympus Stylus 5010 Titanium  Digital Camera
Camera Department: Photo Electronics Department
Camera Item Number: 4
Cameras MP: 14
Camera Stock: 12
Camera Price: $87.54
Restock Fee: 4.38
Total Cameras Inventory: $1050.48

Was This Post Helpful? 0
  • +
  • -

#4 Renagado  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 388
  • Joined: 14-June 09

Re: Adding a subclass and getting the Output

Posted 29 May 2011 - 06:45 PM

Well then combine your code and the idea I just posted, this isn't the neatest way, I just want to guide you without spoiling the fun of learning something :)
You see I added the check there, and then the cast. Without it Java won't know its a DIgitalCameras and you can't access the getMegaPixels() method.
        for( int count = 0; count< Cams.length; count++ )
        {
        	total += Cams[count].getCamerasStock();
        	
            // show inventory information 
            System.out.println();
            System.out.printf( "Cameras %d:\n", count + 1 );
    		System.out.printf( "%s %s\n", "Camera Name:",Cams[count].getCamerasName() );
            System.out.printf( "%s %s\n","Camera Department:",Cams[count].getCamerasDepartment() );
            System.out.printf( "%s %d\n","Camera Item Number:",Cams[count].getCamerasItem() );
            System.out.printf( "%s %d\n", "Camera Stock:", Cams[count].getCamerasStock() );
            System.out.printf( "%s $%.2f\n", "Camera Price:", Cams[count].getCamerasPrice() );
            System.out.printf( "%s $%.2f\n", "Total Cameras Inventory:", Cams[count].getCamerasValue() );


if(cameraList[i] instanceof DigitalCameras)//check if its a DigitalCameras
{
Camera c = (DigitalCameras)cameraList[i];
System.out.printf( "%s %d\n", "Megapixels:", c.getMegaPixels());

}
            System.out.println();
        } //end for loop
        



This post has been edited by Renagado: 29 May 2011 - 06:47 PM

Was This Post Helpful? 1
  • +
  • -

#5 MissZuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Re: Adding a subclass and getting the Output

Posted 29 May 2011 - 07:19 PM

Ok I have added

        	if(Cams[count] instanceof DigitalCameras)//check if its a DigitalCameras
        	{
        	Cameras DigCam = (DigitalCameras)camerasList[count];
        	System.out.printf( "%s %.2f\n", "Megapixels:", ((DigitalCameras) DigCam).getMegaPixels() );
            } 


And still getting same output as before.
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Adding a subclass and getting the Output

Posted 30 May 2011 - 12:02 AM

This is an opportunity to show your instructor that you get OOP (this is for a class, right?) and demonstrate your understanding.

Rather than collecting data from instances of your classes to display the inventory, have the classes themselves provide the methods to collect and correctly present the data. This gives you the advantage of tailoring the output for each of the subclasses where there are differences. With that approach, you don't need to check whether an object is an instance of a certain class. Instead you let each object correctly output the data relevant for that object.

A description of what I mean in words:
Create a method in the super class, Cameras, to print out the inventory.
Create a method in each subclass of Cameras to print out the inventory. The subclass method will first use the super class' method to output inventory details common to all cameras and then add any specifics required for the subclass.
The super class and subclass methods have different names that mean the same thing. For example the super class method might be called showInventory() while each subclass will have a method called displayInventory().

This doesn't require a bunch of new code. Just move the code you've already written into appropriate class methods and then call those methods.
Was This Post Helpful? 0
  • +
  • -

#7 MissZuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Re: Adding a subclass and getting the Output

Posted 30 May 2011 - 09:59 AM

So I understand correctly I am pretty much swapping the code in DigitalCameras for the code in Cameras? This will put all the get/set statements from Cameras into DigitalCameras and vice versa.
Was This Post Helpful? 0
  • +
  • -

#8 Renagado  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 388
  • Joined: 14-June 09

Re: Adding a subclass and getting the Output

Posted 30 May 2011 - 10:14 AM

No, that's not what he meant. He means you override some methods in your DigitalCameras class. To be able to do that, the parent class Cameras needs to have them too. So basically both classes will have some of the same methods. Then you can use what's called polymorphism, which the correct method will be dynamically called. It's hard to explain properly, but take a look at this example:
class Employee {
  public void work() {
    System.out.println("I am an employee.");
  }
}

class Manager extends Employee {
  public void work() {
    System.out.println("I am a manager.");
  }

  public void manage() {
    System.out.println("Managing ...");
  }
}

public class PolymorphismTest1 {
  public static void main(String[] args) {
    Employee employee;
    employee = new Manager();
    System.out.println(employee.getClass().getName());
    employee.work();
    Manager manager = (Manager) employee;
    manager.manage();
  }
}

You see here the manager is added as an employee, but if you run this you'll see the managers code gets called.(To be more precise the static type is Employee, but the dynamic type is Manager) You can use exactly this principle for your project, where Employee would be Cameras and Manager would be DigitalCameras.

This post has been edited by Renagado: 30 May 2011 - 10:15 AM

Was This Post Helpful? 0
  • +
  • -

#9 MissZuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Re: Adding a subclass and getting the Output

Posted 30 May 2011 - 12:04 PM

View PostRenagado, on 30 May 2011 - 10:14 AM, said:

No, that's not what he meant. He means you override some methods in your DigitalCameras class. To be able to do that, the parent class Cameras needs to have them too. So basically both classes will have some of the same methods. Then you can use what's called polymorphism, which the correct method will be dynamically called. It's hard to explain properly, but take a look at this example:
class Employee {
  public void work() {
    System.out.println("I am an employee.");
  }
}

class Manager extends Employee {
  public void work() {
    System.out.println("I am a manager.");
  }

  public void manage() {
    System.out.println("Managing ...");
  }
}

public class PolymorphismTest1 {
  public static void main(String[] args) {
    Employee employee;
    employee = new Manager();
    System.out.println(employee.getClass().getName());
    employee.work();
    Manager manager = (Manager) employee;
    manager.manage();
  }
}

You see here the manager is added as an employee, but if you run this you'll see the managers code gets called.(To be more precise the static type is Employee, but the dynamic type is Manager) You can use exactly this principle for your project, where Employee would be Cameras and Manager would be DigitalCameras.

I think I did as you explained and now I get:
Welcome to Camera Inventory

Cameras 1:
Camera Name: Flip UltraHD U260 Black Video Camera
Camera Department: Video Electronics Department
Camera Item Number: 3
Camera Stock: 7
Camera Price: $99.00
Total Cameras Inventory: $693.00


Cameras 2:
Camera Name: Kodak EasyShare PlayFull Blue-Silver HD Video Camera
Camera Department: Video Electronicss Department
Camera Item Number: 2
Camera Stock: 10
Camera Price: $149.00
Total Cameras Inventory: $1490.00


Cameras 3:
Camera Name: Kodak Easyshare M580 Pink Digital Camera
Camera Department: Photo Electronics Department
Camera Item Number: 5
Camera Stock: 13
Camera Price: $99.88
Total Cameras Inventory: $1298.44


Cameras 4:
Camera Name: Nikon COOLPIX S4100 Value Bundle
Camera Department: Photo Electronics Department
Camera Item Number: 1
Camera Stock: 14
Camera Price: $179.00
Total Cameras Inventory: $2506.00


Cameras 5:
Camera Name: Olympus Stylus 5010 Titanium  Digital Camera
Camera Department: Photo Electronics Department
Camera Item Number: 4
Camera Stock: 12
Camera Price: $87.54
Total Cameras Inventory: $1050.48

Total Inventory Value: $7037.92 
DigitalCameras


My new modified code is:
Inventory
// Inventory.java
// Inventory class

public class Inventory {

	private static DigitalCameras[] camerasList;


	// main begins execution of program
    public static void main( String args [] )
    {

    	
    	// display message
        System.out.println( "Welcome to Camera Inventory" );
    	
        // create array
        Cameras[] Cams = new Cameras[5] ;
        
        Cams[0] = new Cameras("Nikon COOLPIX S4100 Value Bundle","Photo Electronics Department", 1, 14, 179.00);
        Cams[1] = new Cameras("Kodak EasyShare PlayFull Blue-Silver HD Video Camera","Video Electronicss Department", 2, 10, 149.00);
        Cams[2] = new Cameras("Flip UltraHD U260 Black Video Camera","Video Electronics Department", 3, 7, 99.00);
        Cams[3] = new Cameras("Olympus Stylus 5010 Titanium  Digital Camera","Photo Electronics Department", 4, 12, 87.54);
        Cams[4] = new Cameras("Kodak Easyshare M580 Pink Digital Camera","Photo Electronics Department", 5, 13, 99.88);
        
        // sorter for arrays
        bubbleSort( Cams );
        
        double total = 0;
        for( int count = 0; count< Cams.length; count++ )
        {
        	total += Cams[count].getCamerasStock();
        	
            // show inventory information 
            System.out.println();
            System.out.printf( "Cameras %d:\n", count + 1 );
    		System.out.printf( "%s %s\n", "Camera Name:",Cams[count].getCamerasName() );
            System.out.printf( "%s %s\n","Camera Department:",Cams[count].getCamerasDepartment() );
            System.out.printf( "%s %d\n","Camera Item Number:",Cams[count].getCamerasItem() );
            System.out.printf( "%s %d\n", "Camera Stock:", Cams[count].getCamerasStock() );
            System.out.printf( "%s $%.2f\n", "Camera Price:", Cams[count].getCamerasPrice() );
            System.out.printf( "%s $%.2f\n", "Total Cameras Inventory:", Cams[count].getCamerasValue() );
            System.out.println();
        } //end for loop
        

        {
        double totalValue = 0;	
        for(int count = 0; count < Cams.length ; count++ )
			totalValue += Cams[count].getCamerasValue();
        {
        	System.out.printf( "%s $%.2f ", "Total Inventory Value:", totalValue );    
        	System.out.println();
        }
        
        {
        	Cameras Cameras;
        	Cameras = new DigitalCameras(null, null, 0, 0, 0, 0, 0);
        	System.out.printf(Cameras.getClass().getName());
        	Cameras.Cam();
        	DigitalCameras DigitalCameras = (DigitalCameras)Cameras;
        	DigitalCameras.DigCam();
        	

        }
        
        
        } 
        
    } //end main method


	private static void bubbleSort(Cameras[] cams) 
	{
		boolean swapped = true;
		int j = 0;
		Cameras tmp;
		while( swapped)
		{
			swapped = false;
			j++;
			for ( int i = 0; i < cams.length - j; i++)
			{
				if( cams[i].getCamerasName().codePointAt(0) > cams[ i + 1].getCamerasName().charAt(0) )
				{
					tmp = cams[i];
					cams[i] = cams[i + 1];
					cams[i + 1]=tmp;
					swapped = true;
				}
			}
			
		}
	}
           
} // end Inventory class




Cameras
// Cameras.java
// Cameras class

public class Cameras {


    private String camerasName, camerasDepartment; // name of camera and department name
    private int camerasItem, camerasStock; // item number and amount in stock
    private double camerasPrice; // price of cameras


	// create constructors for camera
    public Cameras( String name, String department, int item, int stock, double price )
    {
        camerasName = name;
        camerasDepartment = department;
        camerasItem = item;
        camerasStock = stock;
        camerasPrice = price;
    } // end create constructors 
    
    // set and get for each method
    // camera name
    public void setCamerasName( String name )
    {
        camerasName = name;
    }
    
    public String getCamerasName()
    {
        return camerasName;
    } // end camera name
    
    // camera department
    public void setCamerasDepartment( String department )
    {
        camerasDepartment = department;
    }
    
    public String getCamerasDepartment()
    {
        return camerasDepartment;
    } //end camera department
    
    // camera item
    public void setCamerasItem( int item)
    {
        camerasItem = item;
    }
    
    public int getCamerasItem()
    {
        return camerasItem;
    } // end camera item
    
    // camera stock
    public void setCamerasStock( int stock)
    {
        camerasStock = stock;
    }
    
    public int getCamerasStock()
    {
        return camerasStock;
    } // end camera stock
    
    public void setCamerasPrice( double price )
    {
        camerasPrice = price;
    }
    
    public double getCamerasPrice()
    {
        return camerasPrice;
    } // end camera price and set/get 
    
    // calculate cameras stock value
    public double getCamerasValue()
    {
    	return camerasPrice * camerasStock;
    }
    	
	public int compareTo(Cameras cameras) 
	{
		return 0;
	}
	
	 public void Cam()
	 {
		 System.out.printf("\nINVENTORY INFO\n %s\n %s\n %d\n %d\n $%.2f\n $%.2f\n ", "Cameras Name: ",
	             getCamerasName(), "Cameras Department: ", getCamerasDepartment(),
	             "Cameras Item Number: ", getCamerasItem(), "Cameras In Stock:", getCamerasStock(), 
		         "Cameras Price:", getCamerasPrice(), "Cameras Inventory Value:", getCamerasValue()); 
	 }


} // end Cameras class


Extended Cameras
// DigitalCameras.java
// Extends Cameras class

public class DigitalCameras extends Cameras 
{

	private double resolution = 0.00;
	private double RestockFee = 0.00;

	public DigitalCameras(String name, String department, double megaPixals, int item, int stock,
			double price, double restock)
	{
		super(name, department, item, stock, price);
		
		this.resolution = megaPixals;		
	}
	
	public double getResolution()
	{
		return resolution;
	}
	
	public void setResolution(double megapixels)
	{
		resolution = megapixels;
	}
	
	public double setRestockFee( double restock)
	{
		return 0.05*getCamerasStock()*getCamerasPrice();
	}
	
	public double getRestockFee()
	{
	return RestockFee; 
	}
	
	 public void DigCam()
	 {
		 System.out.printf("\nDigital Cameras Inventory\n %s\n %s\n %.2f\n %d\n %d\n $%.2f\n $%.2f\n ", "Cameras Name: ",
				             getCamerasName(), "Cameras Department: ", getCamerasDepartment(),"Mega Pixels: ", getResolution(),
				             "Cameras Item Number: ", getCamerasItem(), "Cameras In Stock:", getCamerasStock(), 
					         "Cameras Price:", getCamerasPrice(), "Cameras Restock Price:", getRestockFee());
	}
	
} // end Digital Cameras Extended Class




Edited Inventory code to add the Cameras.Cam and DigitalCameras.DigCam and this is the error I get.

DigitalCameras
INVENTORY INFO
Cameras Name:
null
Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.String
at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3999)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2709)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2661)
at java.util.Formatter.format(Formatter.java:2433)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java:821)
at Cameras.Cam(Cameras.java:90)
at Inventory.main(Inventory.java:55)

This post has been edited by MissZuri: 30 May 2011 - 12:25 PM

Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,259
  • Joined: 27-December 08

Re: Adding a subclass and getting the Output

Posted 30 May 2011 - 02:02 PM

The %d formatter represents a base-10 integer. The %s formatter represents a String. Use %s instead of %d for Strings.
Was This Post Helpful? 0
  • +
  • -

#11 MissZuri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 23-May 11

Re: Adding a subclass and getting the Output

Posted 30 May 2011 - 02:55 PM

View Postmacosxnerd101, on 30 May 2011 - 02:02 PM, said:

The %d formatter represents a base-10 integer. The %s formatter represents a String. Use %s instead of %d for Strings.


I am unsure where you are saying I need to change int (%d) a to a string (%s. I understand what these are but what I am trying to out print has a (String name, String department, double megaPixals, int item, int stock, double price, double restock)and it is stopping directly after the first null here:

Line 53 -Cameras = new DigitalCameras(null, null, 0, 0, 0, 0, 0);

I put names and numbers into those parameters and the first name showed but same error comes after at the second null.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1