473,503 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Program Won't Complie

6 New Member
I keep getting one error when I try to compile this program.

public class Employee {

private String name;

private double salary;

private double hours;


public EmployeeSalary() {}


public String getName() {

return name;

}


public void setName(String name) {

name = name;

}


public double getHours() {

return hours;

}


public void displayMessage() {

System.out.print( "The employee " + getName() +

" worked " + getHours());

}

}
Jul 20 '07 #1
8 1780
sicarie
4,677 Recognized Expert Moderator Specialist
prettypirhana-

That's a class. The class needs to be instantiated, usually (for programs of this nature) by a Main class.

What is the error that you're getting?

Please use code tags around your code - they can be found on the right side when you're making a post, or in the Posting Guidelines, and it would be appreciated if you would read them as well.
Jul 20 '07 #2
JosAH
11,448 Recognized Expert MVP
That class is named 'Employee' so that wanabee constructor 'EmployeeSalary'
can never be a proper constructor.

kind regards,

Jos
Jul 20 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
Dang, can't believe I missed that. Good catch, Jos.
Jul 20 '07 #4
prettypirhana
6 New Member
Sorry I submitted the code wrong. That is the frist time I have used this forum. I will remember in the future! Thanks for all of your help! I made the change and the program compiled! Thanks again!
Jul 20 '07 #5
JosAH
11,448 Recognized Expert MVP
Sorry I submitted the code wrong. That is the frist time I have used this forum. I will remember in the future! Thanks for all of your help! I made the change and the program compiled! Thanks again!
Also actually *read* what the compiler has to say to you; your code didn't
compile for no reason; the compiler tries to give you the reason as accurate
as possible. If you don't understand the compiler diagnostic, copy it and post
it here; just saying "help it won't compile" makes it almost impossible for us
to find the cause of the error without actually compiling everything ourself.

kind regards,

Jos
Jul 21 '07 #6
prettypirhana
6 New Member
Here are the errors the compiler gives me. Really, I do not understand most of the errors that the compiler gives me. Here is what my code is supposed to do: Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
• Create a method to calculate the value of the entire inventory.
• Create another method to sort the array items by the name of the product.
As far as I know, I am on the right track of doing this, but I am not for sure.
/tmp/21938/Fish.java:8: cannot find symbol
symbol : class inventory
location: class Fish
new inventory (4);
^
/tmp/21938/Inventory.java:27: cannot find symbol
symbol : method getNumber()
location: class Product[]
System.out.println("Number: " + product.getNumber());
^
/tmp/21938/Inventory.java:28: cannot find symbol
symbol : method getName()
location: class Product[]
System.out.println("Name: " + product.getName());
^
/tmp/21938/Inventory.java:29: cannot find symbol
symbol : method getQuantity()
location: class Product[]
System.out.println("Quantity: " + product.getQuantity());
^
/tmp/21938/Inventory.java:30: cannot find symbol
symbol : method getPrice()
location: class Product[]
System.out.println("Price: " + product.getPrice());
^
/tmp/21938/Inventory.java:32: cannot find symbol
symbol : method getQuantity()
location: class Product[]
product.getQuantity() * product.getPrice());
^
/tmp/21938/Inventory.java:32: cannot find symbol
symbol : method getPrice()
location: class Product[]
product.getQuantity() * product.getPrice());
^
/tmp/21938/Inventory.java:35: operator < cannot be applied to Product[],int
for ( int MAXIUM_ITEMS = 4; product < product.length; product++ )
^
/tmp/21938/Inventory.java:35: operator ++ cannot be applied to Product[]
for ( int MAXIUM_ITEMS = 4; product < product.length; product++ )
^
/tmp/21938/Inventory.java:37: operator + cannot be applied to Product[],int
product + 1, product[product.getName()] );
^
/tmp/21938/Inventory.java:37: cannot find symbol
symbol : method getName()
location: class Product[]
product + 1, product[product.getName()] );
^
/tmp/21938/Inventory.java:39: cannot find symbol
symbol : variable total
location: class Inventory
total = (inventory[ 0 ].getValueOfStock() +
^
/tmp/21938/Inventory.java:39: cannot find symbol
symbol : variable inventory
location: class Inventory
total = (inventory[ 0 ].getValueOfStock() +
^
/tmp/21938/Inventory.java:40: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 1 ].getValueOfStock() +
^
/tmp/21938/Inventory.java:41: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 2 ].getValueOfStock() +
^
/tmp/21938/Inventory.java:42: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 3 ].getValueOfStock() +
^
/tmp/21938/Inventory.java:43: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 4 ].getValueOfStock());
^
/tmp/21938/Inventory.java:44: cannot find symbol
symbol : variable total
location: class Inventory
System.out.printf( "The total value of the inventory is: $%.2f\n\n", total );
^
18 errors

Here is all my codes: (Product.java compiles)

[/code]public class Inventory{


public static final int MAXIMUM_ITEMS = 4;
Product product[] = new Product[MAXIMUM_ITEMS];




public Inventory(){
buildInventory();
getInventory();

}

public void buildInventory() {

product[0] = new Product(1, "Bursa Trigger", 3, 39.99);
product[1] = new Product(2, "Clown Trigger", 1, 74.99);
product[2] = new Product(3, "Blueline Trigger", 2, 59.99);
product[3] = new Product(4, "Queen Trigger", 1, 99.99);

}

public void getInventory() {
for(int i = 0; i < product.length; i++) {
System.out.println("Number: " + product.getNumber());
System.out.println("Name: " + product.getName());
System.out.println("Quantity: " + product.getQuantity());
System.out.println("Price: " + product.getPrice());
System.out.println("Item Value: " +
product.getQuantity() * product.getPrice());
System.out.println();

for ( int MAXIUM_ITEMS = 4; product < product.length; product++ )
System.out.printf( "New Product %2d: %3d\n",
product + 1, product[product.getName()] );
{
total = (inventory[ 0 ].getValueOfStock() +
inventory[ 1 ].getValueOfStock() +
inventory[ 2 ].getValueOfStock() +
inventory[ 3 ].getValueOfStock() +
inventory[ 4 ].getValueOfStock());
System.out.printf( "The total value of the inventory is: $%.2f\n\n", total );

}
}
}
}
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
public class Product
{

private String name;


private int number;


private int units;


private double price;


public Product ( )
{

}



public Product ( String nameIn, int numberIn, int unitsIn, double priceIn, double valueIn )
{

setName (nameIn);
setNumber (numberIn);
setUnits (unitsIn);
setPrice (priceIn);
setValue (valueIn);

}


public void setName( String nameInput )
{

name = nameInput;


}

}

public void setNumber ( int numberInput )
{
[]number = numberInput;

}


public void setUnits ( int unitsInput )
{
units = unitsInput;
}
public void setPrice ( double priceInput )
{
price = priceInput;
}

public String getName ( )
{
return ( name);
}

public double getNumber ( )
{
return ( number );
}

public double getUnits ( )
{
return ( units );
}

public double getPrice ( )
{
return ( price );
}

public double stockValueInDollars()
{
return ( units * price );

}



public String toString()
{
String formatString = "Identification Number : %d\n";
formatString += "Product Name : %s\n";
formatString += "Units In Stock : %d\n";
formatString += "Unit Price : $%.2f\n";
formatString += "Stock Value : $%.2f\n\n";

return String.format ( name(),identificationNumber(), unitsInStock(),unitPriceInDollars(),stockValueInDo llars() );


}


}
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.  
import java.util.Arrays;

public class Fish{

public Fish() {}

public static void main( String args[] ) {
new inventory (4);
}

}[code]
Aug 12 '07 #7
madhoriya22
252 Contributor
/tmp/21938/Fish.java:8: cannot find symbol
symbol : class inventory
location: class Fish
new inventory (4);
^
Hi,
plz have a luk at above error...
  • Here, what java compiler is trying to tell is that u have error at 8th line of ur code.
  • what is the error? Error is that compiler is not able to find symbol.
  • which symbol? symbol is class inventory.(remember java is strongly typed language. So java compiler will read Inventory and inventory as different words)
  • In which class this symbol is? It is in class Fish.
  • And in 8th line this(new inventory(4)) is exactly the place where the error is generating.
Now using same way u can understand and resolve all the errors.
thanks and regards,
madhoriya.
Aug 13 '07 #8
prettypirhana
6 New Member
Hi,
plz have a luk at above error...
  • Here, what java compiler is trying to tell is that u have error at 8th line of ur code.
  • what is the error? Error is that compiler is not able to find symbol.
  • which symbol? symbol is class inventory.(remember java is strongly typed language. So java compiler will read Inventory and inventory as different words)
  • In which class this symbol is? It is in class Fish.
  • And in 8th line this(new inventory(4)) is exactly the place where the error is generating.
Now using same way u can understand and resolve all the errors.
thanks and regards,
madhoriya.
Thanks for your help!
Aug 13 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

13
6566
by: BlackHawke | last post by:
Our program, game program Andromeda Online (www.andromedaonline.net) uses two programs- one to play the game, another to patch the game as updates come out. Players actually launch the updater...
73
7900
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
13
3310
by: Ajay | last post by:
hi! can you call a Python application from a Java program? does this require any additional package to be installed? thanks cheers
55
45913
by: Elijah | last post by:
I have read many of the topics on learning C++ or Java first. It seems like everyone says something different. I would like to know if I should learn C++ or Java. First a little about myself. I...
11
9211
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
14
7292
by: Mick | last post by:
I wrote a C# program that interfaces with a data vendor over the web using an API they supplied and their examples in C#. Now I have another data vendor's API and example that I want to add to...
2
3130
by: Michael | last post by:
Running DB2 v7 UDB ("DB2 v7.1.0.93", "n031208" and "WR21333") on Windows XP, I am unable to find out why the "Build for Debug" option within Stored Procedure Builder is not enabled on Java stored...
8
2428
by: yolazyguy | last post by:
Hello I am new but I have been in a intro programming class with Java as the main entree. I have this program where I need to end input characters at 65 characters and break the line and then add a...
1
1990
by: mshroom12 | last post by:
Hello to all. I am having difficulty trying to do this Java project using Eclipse. The following is what I have to do. Election Day It's almost election day and the election officials need a...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.