Hi everyone,
Hi everyone.
I'm happy to be here today.
actually I need help from u .
I'm doing a JAVA program and there is this error that I really tried to fix but couldn't.
so can u help me please.
the program I'm writing is to accept data from the user " Item serial, units, price " then calculate the retail price of an item and the total price. After that it prints the result on the screen and on a file.
I should use methods and arrays.
Itemserial , units, price are 1D array item description is a 2D array and should be initialized with the following:
Item #....... Description
Item 1....... Jacket
Item 2....... Designer Jeans
Item 3....... Shirt
validation the units between 1 and 1000 and no negative number.
Items serial numbers should not contain more than 6 digits.
The arrays should be parallel.
This is the code I wrote :
import java.util.Scanner; // needed for scanner
import java.io.*; // needed for classes
import java.text.DecimalFormat; // for formating nums
public class RetailItem
{
public static void main(String [] args) throws IOException
{
int itemSerial[];
int units[];
Double price[];
String Desc [][];
Double RetailPrice;
Double totalPrice;
int count;
int row;
int col;
int itemSerial = new int[3];
int units = new int[3];
double price = new double [3];
String Desc = new String [2][3];
//create a decimal format object
DecimalFormat formatter = new DecimalFormat("#,##0.00");
// Use a loop to ask the user to input data and store them in the arrays
for ( int count=0 ; count <3 ; count++ )
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the Item Serial ");
itemSerial[count] = keyboard.nextInt();
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the units ");
units[count] = keyboard.nextInt();
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the price ");
price[count] = keyboard.nextInt();
// insialize the 2Darray with the following
String (Desc [0][0]="Item1",
Desc [0][1]="Item2",
Desc [0][2]="Item3" ,
Desc [1][0]="Jacket" ,
Desc [1][1]="Jeans" ,
Desc [1][2]="Shirt");
}
// valdate unit
while (unit < 0 && unit > 1000)
{
System.out.println(" Invalide Input " );
unit = reader.nextInt();
}
//valdate itemSerial
while(itemSerial < 0 && itemSerial > 1000000 )
{
System.out.println(" Invalide Input " );
itemSerial = reader.nextInt();
}
//valdate price
while(price < 0 )
{
System.out.println(" Invalide Input " );
price = reader.nextInt();
}
// call the methods
getRetailPrice(price);
totalPrice(price,retailPrice);
/** a method to calc the retail price it accepts parameters @parm
then return the value @return */
public double getRetailPrice(double price[])
{
if (price[0])
{
retailPrice = price[0] * 1.12 ;
else
if (price[1])
{
retailPrice = price[1] * 1.16 ;
else
if (price[2])
retailPrice = price[2] * 1.18 ;
}
}
return retailPrice;
}
/** a method to calc the total price it accepts parameters @parm
then return the value @return */
public static double totalPrice(double retailePrice, Price)
{
return double totalPrice = retailePrice * units;
}
FileWriter fwriter = new FileWriter("Report.txt"); // Creat a file
PrintWriter outputFile = new PrintWriter(fwriter); // to write on file
outputFile.println("Item Name \t Serial Number \t Units \t Price \t Retail Price \t Total Price"); // write to the file
outputFile.println("==========================================================================="); // write to the file
// loop to print the description first
for (int row = 0; row < 2; row++)
{
for (int col = 0; col < 3; col++)
{
System.out.println(Desc[row][col]);
}
}
// loop to print the serial,units,price,retailprice,and totalprice
for (int count = 0; count < itemSerial.length; count++)
{
outputFile.println("\t" + itemSerial[count] + " \t" + units[count] + " \t" +
"$"+ (formatter.format(price[count]))+ " \t" +"$"+ (formatter.format(retailPrice)) + " \t" + "$"+ (formatter.format(totalPrice)) );
outputFile.close();
System.out.println( " Data Written to the file " );
}
// To write on screen
System.out.println();
System.out.println("Item Name \t Serial Number \t Units \t Price \t Retail Price \t Total Price");
System.out.println("===========================================================================");
// loop to print the description first
for (int row = 0; row < 2; row++)
{
for (int col = 0; col < 3; col++)
{
System.out.println(Desc[row][col]);
}
}
// loop to print the serial,units,price,retailprice,and totalprice
for (int count = 0; count < itemSerial.length; count++)
{
System.out.println("\t" + itemSerial[count] + " \t" + units[count] + " \t" +
"$"+(formatter.format(price[count]))+ " \t" +"$"+ (formatter.format(retailPrice))+ " \t" + "$"+ (formatter.format(totalPrice)));
}
}
}
we'll the error is in the following method
public double getRetailPrice(double price[])
{
if (price[0])
{
retailPrice = price[0] * 1.12 ;
else
if (price[1])
{
retailPrice = price[1] * 1.16 ;
else
if (price[2])
retailPrice = price[2] * 1.18 ;
}
}
return retailPrice;
}
but I don't get it.
what I'm trying to do here is to get the item's retail price, I should utilize the markup percentage for each item; the markup percentages are12% for Jacket, 16% for Designer Jeans and 18% for Shirt.
I'm really running out of time - Dead line is Sun 3 Jan - and would like for help.
I would appreciate if someone helped me out.
Thank you in advance :)