first of all I really liked the topics here ..
will I'm writing here to ask for help.
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 [][] = { { Item1, Jacket} , { Item2, Jeans} , { Item3, 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
retailPrice(price);
totalPrice(price,retailPrice);
//}
/** a method to calc the retail price it accepts parameters @parm
then return the value @return */
public static double retailePrice(double price )
{
String Desc [][] = { { Item1, Jacket} , { Item2, Jeans} , { Item3, Shirt} };
if(String Desc [0][0] = { { Item1 , Jacket}})
double retailPrice = price * 1.12;
else if ( String Desc [0][1] = { { Item2, Jeans}})
double retailPrice = price * 1.16;
else if ( String Desc [0][2] = { { Item3, Shirt}})
double retailPrice = price * 1.18;
else
double retailPrice = "invaled data";
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 + Price;
}
// call the printing methods
printingOnFile(Desc,itemSerial, units, price, retailPrice, totalPrice);
printingOnScreen(Desc,itemSerial, units, price, retailPrice, totalPrice);
// Print on txt file
public static priningtOnFile (String Desc, int itemSerial,int units, double price, double retailPrice, double totalPrice) throws IOException
{
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 " );
}
}
public static printingOnScreen(String Desc, int itemSerial,int units, double price, double retailPrice, double totalPrice)
{
// 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)));
}
}
;
}
}
and this is the error that the compiler gives me
C:\Users\user\Documents\Uni\COS 260 S1\JAVA\RetailItem.java:86: illegal start of expression public static double retailePrice(double price ) ^ C:\Users\user\Documents\Uni\COS 260 S1\JAVA\RetailItem.java:126: illegal start of expression public static priningtOnFile (String Desc, int itemSerial,int units, double price, double retailPrice, double totalPrice) throws IOException ^ 2 errors Tool completed with exit code 1
I hope you can help me to understand the problem.
please feel free to give your comments.
Thank you

New Topic/Question
Reply




MultiQuote








|