473,395 Members | 2,006 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,395 software developers and data experts.

Java Help!!

17
I'm new to Java and sort of stuck....

this is what i have to do:

Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).
• Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit.
• Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.

this is what i have so far:

Expand|Select|Wrap|Line Numbers
  1. // Product class
  2.  
  3.  
  4. public class Product {
  5.  
  6.     private String title;
  7.     private double item;
  8.     private double stock;
  9.     private double price;
  10.  
  11.     // Constructor to initialize the product information.
  12.     public Product(String title, double item, double stock,
  13.             double price) {
  14.         setTitle(title);
  15.         setItem(item);
  16.         setStock(stock);
  17.         setPrice(price);
  18.  
  19.     }
  20.  
  21.     // Method to get the title
  22.     public String getTitle() {
  23.         return title;
  24.     }
  25.  
  26.     // Method to get the item number
  27.     public double getItem() {
  28.         return item;
  29.     }
  30.  
  31.     //Method to get the stock
  32.     public double getStock() {
  33.         return stock;
  34.     }
  35.  
  36.     //Method to get the price
  37.     public double getPrice() {
  38.         return price;
  39.  
  40.       }
  41.  
  42.     // Method to set the title name.
  43.     public void setTitle(String title) {
  44.         this.title = title;
  45.     }
  46.  
  47.     // Method to set the item number.
  48.     public void setItem(double item) {
  49.         this.item = item;
  50.     }
  51.  
  52.     // Method to set the stock available.
  53.     public void setStock(double stock) {
  54.         this.stock = stock;
  55.     }
  56.  
  57.     //Method to set the price.
  58.     public void setPrice(double price) {
  59.         this.price = price;
  60.  
  61.     }
  62.     // Method to compute the value of inventory.
  63.     public double getInvValue() {
  64.         return this.stock *this.price;
  65.     }
  66.  
  67. }
this is the error i get:

java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.


how do i fix this? do i need to add more? please help!

or am i going about this wrong???
Nov 27 '07 #1
5 1818
Ganon11
3,652 Expert 2GB
It's because you are trying to use the java command on this class - yet you have no main method. You can't say "java myProgram" on a class without a main() method. You should write one that shows that your program works.
Nov 27 '07 #2
Kiamari
17
It's because you are trying to use the java command on this class - yet you have no main method. You can't say "java myProgram" on a class without a main() method. You should write one that shows that your program works.

ok, so how do i do that?????

reminder: i am NEW to java
Nov 27 '07 #3
Ganon11
3,652 Expert 2GB
main() is just a method that looks like this:

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) {
  2.    // ...function body goes here...
  3. }
If you're so new to Java that you haven't ever made a main() method to make objects and use their methods, then you are diving in way too deep. You should not be learning classes before you learn how to do basic programming statements in main().
Nov 28 '07 #4
dlb53
3
Expand|Select|Wrap|Line Numbers
  1. // Inventory class
  2.  
  3.  
  4. public class Inventory {
  5.  
  6.     private String title;
  7.     private double item;
  8.     private double stock;
  9.     private double price;
  10.     private double invValue;
  11.  
  12.     public static void main(String[] args)
  13.     {
  14.  
  15.         // Constructor to initialize the Inventory information.
  16.         public Inventory(String title, double item, double stock,double price)
  17.         {
  18.     setTitle(title);
  19.             setItem(item);
  20.             setStock(stock);
  21.             setPrice(price);
  22.             setInvValue(value);
  23.  
  24.  
  25.     // Method to set the title
  26.         public String setTitle()
  27.         {
  28.             return title;
  29.         }
  30.  
  31.     // Method to set the item number
  32.         public double setItem()
  33.         {
  34.             return item;
  35.         }
  36.  
  37.     //Method to set the stock
  38.         public double setStock()
  39.         {
  40.             return stock;
  41.         }
  42.  
  43.     //Method to set the price
  44.         public double setPrice()
  45.         {
  46.             return price;
  47.         }
  48.  
  49.     // Method to get the title name.
  50.         public void gettitle(String title)
  51.         {
  52.             this.title = title;
  53.         }
  54.  
  55.     // Method to get the item number.
  56.     public void getitem(double item)
  57.     {
  58.         this.item = item;
  59.     }
  60.  
  61.     // Method to get the stock available.
  62.         public void getstock(double stock)
  63.         {
  64.         this.stock = stock;
  65.      }
  66.  
  67.     //Method to get the price.
  68.         public void getPrice(double price)
  69.         {
  70.         this.price = price;
  71.         }
  72.  
  73.     // Method to compute the value of inventory.
  74.         public double getInvValue()
  75.         {
  76.             return this.stock * this.price;
  77.  
  78.           }
  79.     }
  80. }
  81.  
I reworked your program above to include the main() method, which it was missing. However, I am now getting the following errors. And cannot figure out the problem, can someone point out my error:

C:\Users\End User\Documents\TestPrograms\Inventory.java:16: illegal start of expression
public Inventory(String title, double item, double stock,double price)
^
C:\Users\End User\Documents\TestPrograms\Inventory.java:80: ';' expected }
^
C:\Users\End User\Documents\TestPrograms\Inventory.java:80: '}' expected }
^
3 errors

Tool completed with exit code 1

I think we are in the same class.
Feb 27 '08 #5
sukatoa
539 512MB
I reworked your program above to include the main() method, which it was missing. However, I am now getting the following errors. And cannot figure out the problem, can someone point out my error:
C:\Users\End User\Documents\TestPrograms\Inventory.java:16: illegal start of expression
public Inventory(String title, double item, double stock,double price)
^
C:\Users\End User\Documents\TestPrograms\Inventory.java:80: ';' expected }
^
C:\Users\End User\Documents\TestPrograms\Inventory.java:80: '}' expected }
^
3 errors

Tool completed with exit code 1

I think we are in the same class.[/quote]


I think you forgot this,

The Inventory Constructor is inside main method?
You can call it, not like this...

Is the setItem() has a parameter?
Is the setTitle() has a parameter?

hey, when you construct a Set/Get Method, make sure that when you use SetMethod, it should be just to store value.. And the Get Method must return a value...


You have many getmethods that doesn't return any value....
Also in set method...

Try to change it...

Concerned,
Sukatoa.... Shadow Shaman..
Feb 27 '08 #6

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

Similar topics

2
by: ochulus | last post by:
hello! I'm fairly new to java and we're still doing text-based java stuff at school. I just need a bit of help for a project. I know how to read input from the keyboard (e.g. entering a person's...
5
by: H Brown New To It | last post by:
I am very new to Java. How would you go about making Java program that reads in a fixed length text file (myfile.txt) and pass the data into a table in an sql table? The text file data looks...
13
by: Nicholas Pappas | last post by:
Hello all. I am trying to write a Java3D loader for a geometry file from a game, which has Unicode characters (Korean) in it. I wrote the loader and it works in Windows, but I recently brushed...
8
by: Eagle35 | last post by:
hi all im new to the whole java thing and need some help! im trying to make an e mail form and when i test it, it sends the e mail to the designated e mail address but when i go to the e mail...
1
by: iksrazal | last post by:
Hi all, I've been struggling to make this command work from Java: /usr/bin/mysql c4 --user=root --password=mypass -e "source /home/crissilva/c4.sql" Works fine as shown when run from the...
10
by: Mark | last post by:
Hello, I need a some help. I am not a java programmer. I mostly do VB and C#. Here is my problem I have sever side text boxes and when a user tabs off or presses enter I need to have the...
1
by: NITISH SHARMA | last post by:
Plz Can Any One Help Me,i Want To Start Java But I Don't Know How To Start???????????can Anyone Plz Give Me The Name Of Books,or Sites So That I Can Start Learning Java,,,plz???????????????????
1
by: CartmanCreative | last post by:
I am totally new to Java, and would desperately like some help. I have downloaded a Java Text Scroller that uses DHTML to scroll text up and down. There are other Java scrollers that do the same...
1
by: javatech007 | last post by:
The question is below and it is the only one I cant for a project due tomarrow. Question. Write a class called shapes that accepts two variables into its constructor called a and b. Along with...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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,...
0
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...
0
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
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...

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.