473,661 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inventory Java Project Help

11 New Member
I am on the second step of my Inventory Project and can properly run my Inventory2.java file but not my Product2.java file. I get the following error: 71:cannot find symbol, symbol: method getItemTitle() location: class Product
returntitle.com pareTo(p.getIte mTitle());
^

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. // Product2 class
  2.  
  3. import java.util.*;
  4.  
  5. class Product2 implements Comparable {
  6.  
  7.  
  8.     private String title;       // class variable stores the item title
  9.     private long number;      // class variable stores the item number
  10.     private long stockQuantity;   // class variable stores the quantity in stock
  11.     private double price;      // class variable stores the item price
  12.  
  13.     public Product2() {
  14.             title = "";
  15.         number = 0L;
  16.         stockQuantity = 0L;
  17.         price = 0.0;
  18.     }
  19.  
  20.     public Product2(String title, long number, long stockQuantity, double price) {
  21.         this.title = title;
  22.         this.number = number;
  23.         this.stockQuantity = stockQuantity;
  24.         this.price = price;
  25.        }
  26.  
  27.     public void setItemTitle(String title) {
  28.         this.title = title;
  29.     }
  30.  
  31.     public String getItemTitle() {
  32.         return title;
  33.     }
  34.  
  35.     public void setItemNumber(long number) {
  36.         this.number = number;
  37.     }
  38.  
  39.     public long getItemNumber() {
  40.         return number;
  41.     }
  42.  
  43.     public void setStockQuantity(long quantity) {
  44.         stockQuantity = quantity;
  45.     }
  46.  
  47.     public long getStockQuantity() {
  48.         return stockQuantity;
  49.     }
  50.  
  51.     public void setItemPrice(double price) {
  52.         this.price = price;
  53.     }
  54.  
  55.     public double getItemPrice() {
  56.         return price;
  57.     }
  58.  
  59.     public double calculateInventoryValue() {
  60.         return price * stockQuantity;
  61.     }
  62.  
  63.     public int compareTo (Object o) {
  64.         Product p = null;
  65.         try {
  66.             p = (Product)o;
  67.         }
  68.         catch(ClassCastException cE) {
  69.             cE.printStackTrace();
  70.         }
  71.         return title.compareTo(p.getItemTitle());
  72.     }
  73.  
  74.     public String toString() {
  75.         return "DVD Title: "+title + "\nNumber: "+number+"\nPrice: $"+price+"\nQuantity: "+stockQuantity + "\nValue: $"+calculateInventoryValue();
  76.     }
  77.  
  78. } // end class Product2
  79.  

Any suggestions? Thanks! ITQUEST
Feb 18 '07 #1
10 2354
horace1
1,510 Recognized Expert Top Contributor
do you have a method getItemTitle() in Product? I can see a getItemName()? assuming I am looking at the latest version of Product!
Feb 18 '07 #2
ITQUEST
11 New Member
do you have a method getItemTitle() in Product? I can see a getItemName()? assuming I am looking at the latest version of Product!
Yes this is my latest version of Product2. I do not see a getItemName().. .where do you see that? I guess I have been working so long I am getting confused. Do you see the error in my posted code?

Thanks for your help! ITQUEST
Feb 18 '07 #3
horace1
1,510 Recognized Expert Top Contributor
Yes this is my latest version of Product2. I do not see a getItemName().. .where do you see that? I guess I have been working so long I am getting confused. Do you see the error in my posted code?

Thanks for your help! ITQUEST
it looks like the error is in
Expand|Select|Wrap|Line Numbers
  1.     public int compareTo (Object o) {
  2.         Product p = null;
  3.         try {
  4.             p = (Product)o;
  5.         }
  6.         catch(ClassCastException cE) {
  7.             cE.printStackTrace();
  8.         }
  9.         return title.compareTo(p.getItemTitle());
  10.     }
  11.  
in line
Expand|Select|Wrap|Line Numbers
  1. returntitle.compareTo(p.getItemTitle());
  2.  
where p is an object of type Product which does not have a method getItemTitle() but - in the post I am looking at
http://www.thescripts.com/forum/thre...0714-8-10.html
has a method getItemName()

should p be an object of type Product2??
Feb 18 '07 #4
ITQUEST
11 New Member
it looks like the error is in
Expand|Select|Wrap|Line Numbers
  1.     public int compareTo (Object o) {
  2.         Product p = null;
  3.         try {
  4.             p = (Product)o;
  5.         }
  6.         catch(ClassCastException cE) {
  7.             cE.printStackTrace();
  8.         }
  9.         return title.compareTo(p.getItemTitle());
  10.     }
  11.  
in line
Expand|Select|Wrap|Line Numbers
  1. returntitle.compareTo(p.getItemTitle());
  2.  
where p is an object of type Product which does not have a method getItemTitle() but - in the post I am looking at
http://www.thescripts.com/forum/thre...0714-8-10.html
has a method getItemName()

should p be an object of type Product2??

Yes I believe so. I changed that part of the code to read as this:

public int compareTo (Object o) {
Product2 p = null;
try {
p = (Product2)o;
}
catch(ClassCast Exception cE) {
cE.printStackTr ace();
}
return title.compareTo (p.getItemTitle ());
}

And tried to run it. It gives me the error: Exception in Thread "Main" java lang. NoSuchMethodErr or: main

ITQUEST
Feb 18 '07 #5
horace1
1,510 Recognized Expert Top Contributor
you need a main() method, something along the lines of
Expand|Select|Wrap|Line Numbers
  1. public static void main(String s[])
  2. {
  3.   Product2 p = new Product2();
  4.   // more code????
  5. }
  6.  
Feb 18 '07 #6
ITQUEST
11 New Member
you need a main() method, something along the lines of
Expand|Select|Wrap|Line Numbers
  1. public static void main(String s[])
  2. {
  3.   Product2 p = new Product2();
  4.   // more code????
  5. }
  6.  
I am not sure if I understand. I have changed the code in the beginning to look like this:

// Product2 class

import java.util.*;

public static void main (String args[])
Product2 p = new Product2();

class Product2 implements Comparable {


private String title; // class variable stores the item title
private long number; // class variable stores the item number
private long stockQuantity; // class variable stores the quantity in stock
private double price; // class variable stores the item price
...

And it doesn't work either. I think I am confusing myself more than I should be.
ITQUEST
Feb 18 '07 #7
Ganon11
3,652 Recognized Expert Specialist
Well, in order for you to execute a command like

Expand|Select|Wrap|Line Numbers
  1. java Product2
there has to be a function main() in the class, as horace said. You will use this main function to test out the class, etc. Alternatively, you may have been given a 'main' class to execute for testing, in which case you would use

Expand|Select|Wrap|Line Numbers
  1. java MainClass
instead of Product2.
Feb 18 '07 #8
horace1
1,510 Recognized Expert Top Contributor
I am not sure if I understand. I have changed the code in the beginning to look like this:

// Product2 class

import java.util.*;

public static void main (String args[])
Product2 p = new Product2();

class Product2 implements Comparable {


private String title; // class variable stores the item title
private long number; // class variable stores the item number
private long stockQuantity; // class variable stores the quantity in stock
private double price; // class variable stores the item price
...

And it doesn't work either. I think I am confusing myself more than I should be.
ITQUEST
put the main() including the {} inside the class not outside
Feb 18 '07 #9
ITQUEST
11 New Member
put the main() including the {} inside the class not outside

I worked on it and got it to run! Thanks so much for your help!
When I get to the next step of my assignment can I post any questions under this same thread or should I start a new one?

ITQUEST
Feb 18 '07 #10

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

Similar topics

5
2399
by: xiebopublic | last post by:
Hi all, I want to build a corresponding c++ version for a big java project (e.g. Geotools(www.geotools.org))? Which is the quickest/easiest way? I don't want to use the Java VM, then JNI is not suitable. I know this is a open issue, and I want to know your options. Thank you!
1
1475
by: Meiaad | last post by:
I have a java project. this project is stock market monitoring system. our jop is to download the source of the html page using eclips. and i success to do that but the problem is how can i search from this source using java. and print the result of the search for the user. please help me as soon as possible thank you this is my code public class URLConnectionReader { public static void main(String args) throws Exception { ...
4
1103
by: mrityunjay11 | last post by:
hi iam starting to learn java can anybody suggest me good java project topic
0
806
by: srikanta | last post by:
hi, when I am trying to run a java project in J#(Visual Studio 2005).the project compile successfully without any error but at run time "UnsatisfiedLinkError " what is the solution of this please specify
1
1865
by: SquatterMadras | last post by:
Hi there, My friend and I (both completely new to Java, but programmers in other languages) have inherited a large Java project and we are not sure where to start on it. The author has passed on all source files to us, and some basic instructions involving Maven, Eclipse, etc. etc.. We think we've managed to get everything installed as he suggested, and the project loaded into Eclipse - we're just not really sure where to go from here -...
0
1643
by: ycinar | last post by:
hey all, i am working on a Java project using JBuilder.. when i build my code its fine, but when comes to run, it doesnt run and displays the following logs.. i think there is JDK conflict.. actually when i build it, it creates a jar file which is totally fine (i can confirm that because i use that jar file in another project) any idea on how to get around this? maybe i could try to run it from the command line, but dont know how to run...
1
2005
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...
2
2792
by: sunsom | last post by:
hi all, i have a requirement to send FAX through java code. how can i do a fax in java..kindly help!!!. what API is there for FAX....(free API).
7
1985
by: javaprojectreq | last post by:
hi, as a part of my java project ihave to encode voice,compress it,decode voice,decompress .can anyone help me to write code for the same.Its urgent
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8855
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...
0
8758
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7364
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
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...
1
2762
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
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.