I keep gettting an error when I try to run this program it says that I am missing a format specifier, I chacked and cannot find where it is missing everything is there.
The error message when ran is:
Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier 's'
at java.util.Formatter.format(Formatter.java:2431)
at java.io.PrintStream.format(PrintStream.java:920)
at java.io.PrintStream.printf(PrintStream.java821)
at Inventory2.printString(Inventory2.java:177)
at Pens.stringPrint(Pens.java:83)
at PensTest.main(PensTest.java:21)
The superclass is Inventory2
//Nicole Hammers
//Inventory2
import java.util.Arrays;
public class Inventory2
{
private String productName[];
private String productNum[];
private String temp[];
private double productUnits[];
private double productPrice[];
private int b;
public Inventory2( String itemName[], String itemNum[], String arraytemp[], double amountUnits[], double pricePerUnit[], int a )
{
temp = arraytemp;
sortProductName( itemName );
sortProductNum( itemNum, arraytemp, itemName );
sortProductUnit( amountUnits, arraytemp, itemName );
sortProductPrice( pricePerUnit, arraytemp, itemName );
setCounter( a );
}
public String[] getTemp( String arraytemp[] )
{
temp = arraytemp;
return temp;
}
public String[] getProductName( String itemName[] )
{
sortProductName( itemName );
return productName;
}
public String[] getProductNum( String itemNum[], String arraytemp[], String itemName[] )
{
sortProductNum( itemNum, arraytemp, itemName );
return productNum;
}
public double[] getProductPrice( double pricePerUnit[], String arraytemp[], String itemName[] )
{
sortProductPrice( pricePerUnit, arraytemp, itemName );
return productPrice;
}
public double[] getProductUnits( double amountUnits[], String arraytemp[], String itemName[] )
{
sortProductUnit( amountUnits, arraytemp, itemName );
return productUnits;
}
public String[] sortProductName( String itemName[] )
{
productName = itemName;
Arrays.sort( productName );
return productName;
}
public int setCounter( int a )
{
b = a;
return b;
}
public double findIndBaseTot( double price[], double units[], int b )
{
double indBase;
indBase = price[ b ] * units[ b ];
return indBase;
}
public double findAllBase( double productUnits[], double productPrice[] )
{
double total = 0;
for ( int c = 0; c < productUnits.length; c++ )
{
total += productUnits[ c ] * productPrice[ c ];
}
return total;
}
public String[] sortProductNum( String itemNum[], String arraytemp[], String itemName[] )
{
temp = getTemp( arraytemp );
productName = sortProductName( itemName );
String arraynew[] = new String[4];
for ( int c = 0; c < productName.length; c++ )
{
for ( int d = 0; d < productName.length; d++ )
{
if ( productName[ c ].equals( temp[ d ] ) )
{
arraynew[ c ] = itemNum[ d ];}
}
}
productNum = arraynew;
return productNum;
}
public double[] sortProductUnit( double amountUnits[], String arraytemp[], String itemName[] )
{
temp = getTemp( arraytemp );
productName = sortProductName( itemName );
double arraynew[] = new double[4];
for ( int c = 0; c < productName.length; c++ )
{
for ( int d = 0; d < productName.length; d++ )
{
if ( productName[ c ].equals( temp[ d ] ) )
{
arraynew[ c ] = amountUnits[ d ];}
}
}
productUnits = arraynew;
return productUnits;
}
public double[] sortProductPrice( double pricePerUnit[], String arraytemp[], String itemName[] )//Sorts double type array according to how string type array is sorted.
{
temp = getTemp( arraytemp );
productName = sortProductName( itemName );
double arraynew[] = new double[4];
for ( int c = 0; c < productName.length; c++ )
{
for ( int d = 0; d < productName.length; d++ )
{
if ( productName[ c ].equals( temp[ d ] ) )
{
arraynew[ c ] = pricePerUnit[ d ];}
}
}
productPrice = arraynew;
return productPrice;
}
public void printString( String itemName[], String arraytemp[], String itemNum[], double amountUnits[], double pricePerUnit[], int a )
{
productName = getProductName( itemName );
productNum = getProductNum( itemNum, arraytemp, itemName );
productUnits = getProductUnits( amountUnits, arraytemp, itemName );
productPrice = getProductPrice( pricePerUnit, arraytemp, itemName );
b = setCounter( a );
System.out.printf( "%s: %17s \n%s: %15s \n%s :%21.2f \n%s: $%18.2f \n%s: $%19.2f \n%s: $%17.2f \n ", "Product Name", productName[ b ], "Product Number", productNum[ b ], "Quantity", productUnits[ b ], "Unit Price", productPrice[ b ], "Base Cost", findIndBaseTot( productPrice, productUnits, b ) );
}
}
the subclass
//Subclass Pens
import java.util.Arrays;
public class Pens extends Inventory2
{
private double refee;
public Pens( String itemName[], String itemNum[], String arraytemp[], double amountUnits[], double pricePerUnit[], int a )
{
super( itemName, itemNum, arraytemp, amountUnits, pricePerUnit, a );
}
public int callcounter( int a )
{
a = super.setCounter(a);
return a;
}
public double findRestockFee( double price[], double units[], int a )
{
double fee;
fee = super.findIndBaseTot( price, units, a ) * .05;
return fee;
}
public double findIndTot( double price[], double units[], int a )
{
double fee;
double base;
double indTot;
fee = super.findIndBaseTot( price, units, a ) * .05;
base = super.findIndBaseTot( price, units, a );
indTot = base + fee;
return indTot;
}
public double findTot( double productUnits[], double productPrice[] )
{
double fee = 0;
double total = 0;
fee = super.findAllBase( productUnits, productPrice ) * .05;
total = super.findAllBase( productUnits, productPrice ) + fee;
return total;
}
public double findTotUnits( double amountUnits[] )
{
double total = 0;
for ( int a = 0; a < amountUnits.length; a++ )
{
total += amountUnits[ a ];
}
return total;
}
public double findAllFee( double amountUnits[], double pricePerUnit[] )
{
double fee;
fee = super.findAllBase( amountUnits, pricePerUnit ) * .05;
return fee;
}
public void stringPrint( String itemName[], String arraytemp[], String itemNum[], double amountUnits[], double pricePerUnit[], int a )
{
super.printString( itemName, arraytemp, itemNum, amountUnits, pricePerUnit, a );
}
public void print( String itemName[], String arraytemp[], String itemNum[], double amountUnits[], double pricePerUnit[], int a )
{
double refee = findRestockFee( pricePerUnit, amountUnits, a );
double indTot = findIndTot( pricePerUnit, amountUnits, a );
System.out.printf( "Restocking Fee:$%17.2f \n%s: $%17.2f \n\n", refee, "Total Cost", indTot );
}
public void printAll( String itemName[], double amountUnits[], double pricePerUnit[] )
{
System.out.printf( "%s: %17.2f \n%s: $%17.2f \n%s:$ %17.2f \n%s:$ %.2f \n", "Total Units of Pens", findTotUnits( amountUnits ), "Base Cost of Pens", super.findAllBase( amountUnits, pricePerUnit ), "Restock Fee of Pens", findAllFee( amountUnits, pricePerUnit ), "Total Cost of Pens", findTot( amountUnits, pricePerUnit ) );
}
}
and the the program to make it all work
//InventoryMain
public class PensTest
{
public static void main( String args[] )
{
String itemName[] = { "Fine Point", "Ball Point", "Gell", "Retractable" };
String arraytemp[] = { "Fine Point", "Ball Point", "Gell", "Retractable" };
String itemNum[] = { "123456", "234567", "345678", "456789"};
double amountUnits[] = { 23, 16, 27, 11 };
double pricePerUnit[] = { 3.99, 1.99, 2.99, 3.49 };
int a = 0;
Pens pens = new Pens( itemName, arraytemp, itemNum, amountUnits, pricePerUnit, a );
for ( a = 0 ; a < itemName.length; a++ )
{
pens.callcounter( a );
pens.stringPrint( itemName, arraytemp, itemNum, amountUnits, pricePerUnit, a );
pens.print( itemName, arraytemp, itemNum, amountUnits, pricePerUnit, a );
}
pens.printAll( itemName, amountUnits, pricePerUnit );
}
}
I know I'm missing something but I cannot figure out what.