473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Inventory Java Project Help

11
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.compareTo(p.getItemTitle());
^

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 2335
horace1
1,510 Expert 1GB
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
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 Expert 1GB
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
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(ClassCastException cE) {
cE.printStackTrace();
}
return title.compareTo(p.getItemTitle());
}

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

ITQUEST
Feb 18 '07 #5
horace1
1,510 Expert 1GB
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
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 Expert 2GB
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 Expert 1GB
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
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
Ganon11
3,652 Expert 2GB
You should probably start a new thread if you have any questions.
Feb 18 '07 #11

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

Similar topics

5
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...
1
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...
4
by: mrityunjay11 | last post by:
hi iam starting to learn java can anybody suggest me good java project topic
0
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...
1
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...
0
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.. ...
1
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...
2
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.