I am stuck trying to figure out syntax errors in program.
Would appreciate help.

Thank You In Advance :D

These are the errors:

C:\My Documents\myJavaFiles\Homework 2\Inventory.java:40: illegal character: \92
System.out.println("Item Already Exists --" \' +item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:40: unclosed character literal
System.out.println("Item Already Exists --" \' +item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:40: illegal character: \92
System.out.println("Item Already Exists --" \' +item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:40: unclosed character literal
System.out.println("Item Already Exists --" \' +item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:51: illegal character: \92
System.out.print("Cannot find specified item -" \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:51: unclosed character literal
System.out.print("Cannot find specified item -" \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:51: illegal character: \92
System.out.print("Cannot find specified item -" \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:51: unclosed character literal
System.out.print("Cannot find specified item -" \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:80: illegal character: \92
System.out.print("Cannot find specified item - " \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:80: unclosed character literal
System.out.print("Cannot find specified item - " \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:80: illegal character: \92
System.out.print("Cannot find specified item - " \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:80: unclosed character literal
System.out.print("Cannot find specified item - " \' + item + \');
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:119: ')' expected
public void update(String item, double priceAdjPercent = 0.25)
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:145: ';' expected
private int findItemIndex(String item)
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:147: 'class' or 'interface' expected
int i;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:149: 'class' or 'interface' expected
for(i=0; i=maxIndex; i++)
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:157: 'class' or 'interface' expected
}//end findIndexItem
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:158: 'class' or 'interface' expected
}//end Inventory
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:8: class inventory is public, should be declared in a file named inventory.java
public class inventory
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:23: cannot resolve symbol
symbol  : variable items
location: class inventory
items = new String [ARRAY_SIZE];
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:30: cannot resolve symbol
symbol  : method findItemIndex (java.lang.String)
location: class inventory
int index = findItemIndex(item);
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:34: cannot resolve symbol
symbol  : variable items
location: class inventory
items [maxIndex] = item;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:35: array required, but int found
quantity [maxIndex] = quantity;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:36: array required, but double found
price [maxIndex] = price;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:48: cannot resolve symbol
symbol  : method findItemIndex (java.lang.String)
location: class inventory
int index = findItemIndex(item);
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:55: array required, but int found
quantity[index] = quantity;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:62: cannot resolve symbol
symbol  : method findItemIndex (java.lang.String)
location: class inventory
int index = findItemIndex(item);
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:77: cannot resolve symbol
symbol  : method findItemIndex (java.lang.String)
location: class inventory
int index = findItemIndex(item);
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:84: array required, but double found
price[index] = price;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:91: cannot resolve symbol
symbol  : method findItemIndex (java.lang.String)
location: class inventory
int index = findItemIndex(item);
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:106: cannot resolve symbol
symbol  : method findItemIndex (java.lang.String)
location: class inventory
int index = findItemIndex(item);
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:119: missing method body, or declare abstract
public void update(String item, double priceAdjPercent = 0.25)
^
32 errors

This is the code:

* This program is to help Price Chopper with their inventory tracking.
*********************************************************/


public class inventory
{
private final int ARRAY_SIZE = 100;
int [] quantity;                      // quantity of items in inventory
double [] price;                 //prices of items in inventory
String[] item;                   //names of inventory items
int maxIndex = -1;                       //index of last filled item



/********************************************************/
//0-parameter constructor
public void inventory()
{
quantity = new int[ARRAY_SIZE];
price = new double [ARRAY_SIZE];
items = new String [ARRAY_SIZE];


} //end Inventory
/********************************************************/
//newItem method
public void newItem(String item, int quantity, double price)
{
int index = findItemIndex(item);
if(index == -1)
{
maxIndex ++;
items [maxIndex] = item;
quantity [maxIndex] = quantity;
price [maxIndex] = price;
}
else
{
System.out.println("Item Already Exists --" \' +item + \');
}


} //end newItem
/********************************************************/
//setQuantity method
public int setQuantity(int quantity, String item)
{
int index = findItemIndex(item);
if(index == -1)
{
System.out.print("Cannot find specified item -" \' + item + \');
}
else
{
quantity[index] = quantity;
}
}//end setQuantity
/********************************************************/
//getQuantity method
public int getQuanity(String item)
{
int index = findItemIndex(item);
if(index == -1)
{
System.out.print("Cannot find specified item");
return 0;
}
else
{
return quantity [index];
}
}//end getQuantity
/********************************************************/
//setPrice method
public double setPrice(String item, double price)
{
int index = findItemIndex(item);
if(index == -1)
{
System.out.print("Cannot find specified item - " \' + item + \');
}
else
{
price[index] = price;
}
}//end setPrice
/********************************************************/
//getPrice method
public double getPrice(String item)
{
int index = findItemIndex(item);
if(index == -1)
{
System.out.print("Cannot find specified item");
return 0;
}
else
{
return price [index];
}
}//end getPrice
/********************************************************/
//update method
public void update(String item, int quantityIncrease)
{
int index = findItemIndex(item);
if(index == -1)
{
System.out.print("Cannot find specified item");


}
else
{
quantity[index]+= quantityIncrease;
}
}//end update
/********************************************************/
//update method 2
public void update(String item, double priceAdjPercent = 0.25)
{
int index = findItemIndex(item);
if(index == -1)
{
System.out.print("Cannot find specified item");


}
else
{
price[index]+= price[index] * priceAdjPercent;


}
}//end update
/********************************************************/
//stock report method
public void stockReport()
{
int i;
for(i=0; i< maxIndex; i++)
{
System.out.println(item + " - in stock: "+quantity + "; price: $ " + price;
}
}//end report method
/********************************************************/
//helping method ItemIndex
private int findItemIndex(String item)
}
int i;


for(i=0; i=maxIndex; i++)
{
if(item.equals(item))
{
return i;
}
}
return -1;
}//end findIndexItem
}//end Inventory

I'll help you with the System.outs to get rid of the bulk of the problem, but I am very sick right now, or else I would help you fix all of it.

System.out.print("Cannot find specified item -" \' + item + \');

should be something like this"

System.out.print("Cannot find specified item -" + "\\" + item + "\\");

also, if you want to convert an int to a string, do it like this:

int index = Integer.parseInt(findItemIndex(item));

Sorry I can't help right now...

Thank you server crash that helped with those issues that I was having.

I am still open to other suggestions because I am still getting these error messages:

C:\My Documents\myJavaFiles\Homework 2\Inventory.java:128: ')' expected
public void update(String item, double priceAdjPercent = 0.25)
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:155: ';' expected
private int findItemIndex(String item)
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:157: 'class' or 'interface' expected
int i;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:159: 'class' or 'interface' expected
for(i=0; i=maxIndex; i++)
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:167: 'class' or 'interface' expected
}//end findIndexItem
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:168: 'class' or 'interface' expected
}//end Inventory
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:8: class inventory is public, should be declared in a file named inventory.java
public class inventory
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:23: cannot resolve symbol
symbol : variable items
location: class inventory
items = new String [ARRAY_SIZE];
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:30: cannot resolve symbol
symbol : method findItemIndex (java.lang.String)
location: class inventory
int index = Integer.parseInt(findItemIndex(item));
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:35: cannot resolve symbol
symbol : variable items
location: class inventory
items [maxIndex] = item;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:36: array required, but int found
quantity [maxIndex] = quantity;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:37: array required, but double found
price [maxIndex] = price;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:49: cannot resolve symbol
symbol : method findItemIndex (java.lang.String)
location: class inventory
int index = Integer.parseInt(findItemIndex(item));
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:58: array required, but int found
quantity[index] = quantity;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:65: cannot resolve symbol
symbol : method findItemIndex (java.lang.String)
location: class inventory
int index = Integer.parseInt(findItemIndex(item));
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:81: cannot resolve symbol
symbol : method findItemIndex (java.lang.String)
location: class inventory
int index = Integer.parseInt(findItemIndex(item));
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:91: array required, but double found
price[index] = price;
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:98: cannot resolve symbol
symbol : method findItemIndex (java.lang.String)
location: class inventory
int index = Integer.parseInt(findItemIndex(item));
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:114: cannot resolve symbol
symbol : method findItemIndex (java.lang.String)
location: class inventory
int index = Integer.parseInt(findItemIndex(item));
^
C:\My Documents\myJavaFiles\Homework 2\Inventory.java:128: missing method body, or declare abstract
public void update(String item, double priceAdjPercent = 0.25)
^
20 errors

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.