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: -
// Product2 class
-
-
import java.util.*;
-
-
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
-
-
public Product2() {
-
title = "";
-
number = 0L;
-
stockQuantity = 0L;
-
price = 0.0;
-
}
-
-
public Product2(String title, long number, long stockQuantity, double price) {
-
this.title = title;
-
this.number = number;
-
this.stockQuantity = stockQuantity;
-
this.price = price;
-
}
-
-
public void setItemTitle(String title) {
-
this.title = title;
-
}
-
-
public String getItemTitle() {
-
return title;
-
}
-
-
public void setItemNumber(long number) {
-
this.number = number;
-
}
-
-
public long getItemNumber() {
-
return number;
-
}
-
-
public void setStockQuantity(long quantity) {
-
stockQuantity = quantity;
-
}
-
-
public long getStockQuantity() {
-
return stockQuantity;
-
}
-
-
public void setItemPrice(double price) {
-
this.price = price;
-
}
-
-
public double getItemPrice() {
-
return price;
-
}
-
-
public double calculateInventoryValue() {
-
return price * stockQuantity;
-
}
-
-
public int compareTo (Object o) {
-
Product p = null;
-
try {
-
p = (Product)o;
-
}
-
catch(ClassCastException cE) {
-
cE.printStackTrace();
-
}
-
return title.compareTo(p.getItemTitle());
-
}
-
-
public String toString() {
-
return "DVD Title: "+title + "\nNumber: "+number+"\nPrice: $"+price+"\nQuantity: "+stockQuantity + "\nValue: $"+calculateInventoryValue();
-
}
-
-
} // end class Product2
-
Any suggestions? Thanks! ITQUEST
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!
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
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 -
public int compareTo (Object o) {
-
Product p = null;
-
try {
-
p = (Product)o;
-
}
-
catch(ClassCastException cE) {
-
cE.printStackTrace();
-
}
-
return title.compareTo(p.getItemTitle());
-
}
-
in line -
returntitle.compareTo(p.getItemTitle());
-
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??
it looks like the error is in -
public int compareTo (Object o) {
-
Product p = null;
-
try {
-
p = (Product)o;
-
}
-
catch(ClassCastException cE) {
-
cE.printStackTrace();
-
}
-
return title.compareTo(p.getItemTitle());
-
}
-
in line -
returntitle.compareTo(p.getItemTitle());
-
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
horace1 1,510
Recognized Expert Top Contributor
you need a main() method, something along the lines of -
public static void main(String s[])
-
{
-
Product2 p = new Product2();
-
// more code????
-
}
-
you need a main() method, something along the lines of -
public static void main(String s[])
-
{
-
Product2 p = new Product2();
-
// more code????
-
}
-
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
Ganon11 3,652
Recognized Expert Specialist
Well, in order for you to execute a command like
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
instead of Product2.
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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!
|
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 {
...
|
by: mrityunjay11 |
last post by:
hi iam starting to learn java can anybody suggest me good java project topic
|
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
|
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 -...
| |
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...
|
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...
|
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).
|
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
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |