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.

New Topic/Question
Reply



MultiQuote







|