473,656 Members | 2,793 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.prin t( "The employee " + getName() +

" worked " + getHours());

}

}
Jul 20 '07 #1
8 1785
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.prin tln("Number: " + product.getNumb er());
^
/tmp/21938/Inventory.java: 28: cannot find symbol
symbol : method getName()
location: class Product[]
System.out.prin tln("Name: " + product.getName ());
^
/tmp/21938/Inventory.java: 29: cannot find symbol
symbol : method getQuantity()
location: class Product[]
System.out.prin tln("Quantity: " + product.getQuan tity());
^
/tmp/21938/Inventory.java: 30: cannot find symbol
symbol : method getPrice()
location: class Product[]
System.out.prin tln("Price: " + product.getPric e());
^
/tmp/21938/Inventory.java: 32: cannot find symbol
symbol : method getQuantity()
location: class Product[]
product.getQuan tity() * product.getPric e());
^
/tmp/21938/Inventory.java: 32: cannot find symbol
symbol : method getPrice()
location: class Product[]
product.getQuan tity() * product.getPric e());
^
/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 ].getValueOfStoc k() +
^
/tmp/21938/Inventory.java: 39: cannot find symbol
symbol : variable inventory
location: class Inventory
total = (inventory[ 0 ].getValueOfStoc k() +
^
/tmp/21938/Inventory.java: 40: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 1 ].getValueOfStoc k() +
^
/tmp/21938/Inventory.java: 41: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 2 ].getValueOfStoc k() +
^
/tmp/21938/Inventory.java: 42: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 3 ].getValueOfStoc k() +
^
/tmp/21938/Inventory.java: 43: cannot find symbol
symbol : variable inventory
location: class Inventory
inventory[ 4 ].getValueOfStoc k());
^
/tmp/21938/Inventory.java: 44: cannot find symbol
symbol : variable total
location: class Inventory
System.out.prin tf( "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.prin tln("Number: " + product.getNumb er());
System.out.prin tln("Name: " + product.getName ());
System.out.prin tln("Quantity: " + product.getQuan tity());
System.out.prin tln("Price: " + product.getPric e());
System.out.prin tln("Item Value: " +
product.getQuan tity() * product.getPric e());
System.out.prin tln();

for ( int MAXIUM_ITEMS = 4; product < product.length; product++ )
System.out.prin tf( "New Product %2d: %3d\n",
product + 1, product[product.getName ()] );
{
total = (inventory[ 0 ].getValueOfStoc k() +
inventory[ 1 ].getValueOfStoc k() +
inventory[ 2 ].getValueOfStoc k() +
inventory[ 3 ].getValueOfStoc k() +
inventory[ 4 ].getValueOfStoc k());
System.out.prin tf( "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 stockValueInDol lars()
{
return ( units * price );

}



public String toString()
{
String formatString = "Identifica tion 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(),identifi cationNumber(), unitsInStock(), unitPriceInDoll ars(),stockValu eInDollars() );


}


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

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.(reme mber 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.(reme mber 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
6587
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 which checks for fresh updates, then installs them, then launches the game client. We have begun our beta test, and would like to have the client open with a console window so that players can see exceptions that are thrown. How to do this seems to...
73
7986
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 as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only LISP has rationals as far as I can tell. Because CL supports keyword arguments, it has a wider range...
13
3331
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
45982
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 know PHP, BASIC, and of course HTML. I'll be 15 years old in September. I am interested in programming GUI applications. I am also interested in programming games. I know that I should learn C++ to program games, but would learning Java make the...
11
9241
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 C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
14
7319
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 my C# program. But this new API is written in Java. They gave me an example source code that uses their API but the actual API looks like it is stored in a few .jar files. I unzipped those .jar files into many .class files. I think these .class...
2
3142
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 procedures. It is enabled for SQL stored procedures. It is possible to "Build" and "Run" the Java SPs, it just isn't possible to click on the "Build for Debug" option. Thanks for any help in advance. Michael
8
2436
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 new line. This is my code: import static java.lang.System.*; import java.util.Scanner; class formatter3 { public static void main (String args) {
1
2004
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 program to help tally election results. There are two candidates for office -- Polly Tichen and Ernest Orator. The program's job is to take as input the number of votes each candidate received in each voting precinct and find the total number of votes for...
0
8297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8498
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8600
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.