5 Replies - 194 Views - Last Post: 20 November 2012 - 06:45 AM Rate Topic: -----

#1 Odko  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 25-October 12

Representing a product that small company sells.

Posted 20 November 2012 - 02:51 AM

Greetings everyone .
I need to make program according to this excersice. I have wrote some code but still i do not understand what exactly suppose to do. Please guys help me.
Write a class, Product, that could be used for representing a product that a small company
sells. It should be possible to store the following information about each product. An
identifier, i.e. a product number (use an integer), a product name (use a string), price (float
should be used), order point (integer), units in store (integer) and product description (string).
The class should have the following methods:
A constructor
A method that returns the units of items in store
A method for deliverance to the store (increases the units of this product)
A method for withdrawal from the store (decreases the units of this product)
Please note that if one of the methods changes the stored items below the order point a
message should be printed. It should also be impossible to have a negative amount of items.

// code
public class Product {
String productnumber;
String productname;
String price;
String orderpoint;
String unitsInStore;

public String Product(String productnamber, String productname, String price, String orderpoint, String unitsInStore){

return unitsInStore;

}
}

Is This A Good Question/Topic? 0
  • +

Replies To: Representing a product that small company sells.

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Representing a product that small company sells.

Posted 20 November 2012 - 03:33 AM

Improvements to make:

Post your code in code tags.
Use variable types as required - not all Strings
Constructors don't have return types
You may want multiple constructors (but start with one)
Add the required method to return units of items
Add the required method for adding units of existing items to stock
Add the required method for reducing units of existing items to stock

Ensure the method that reduces:
Checks the order point and prints a message to order more
Won't decrease the number of units below zero.
Was This Post Helpful? 0
  • +
  • -

#3 Odko  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 25-October 12

Re: Representing a product that small company sells.

Posted 20 November 2012 - 03:49 AM

Thank you for your reply.
I understand the requirements but i do not understand how to create methods. this is my problem
Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Representing a product that small company sells.

Posted 20 November 2012 - 04:10 AM

At first you don't understand exactly what you're supposed to do, and now you don't understand how to create methods. Volunteer time here is portioned to those who ask clear, understandable questions that have bounded answers. Continued vagueness or broad "what is the meaning of life" questions from you will be ignored. Please be specific in what you need help with.

Review your textbook on methods, and here's the Oracle tutorial on methods.
Was This Post Helpful? 0
  • +
  • -

#5 Odko  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 37
  • Joined: 25-October 12

Re: Representing a product that small company sells.

Posted 20 November 2012 - 06:32 AM

public class Product {
     int productnumber;
     String productname;
     float price;
     int orderpoint;
     int  unitsInStore;
     String productdiscription;
  public Product(int productnumber, String productname, float price, int orderpoint, int unitsInStore, String productdiscription){
	  this.productnumber = 0;
	  this.productname = productname;
	  this.price = 0;
	  this.orderpoint = 0;
	  this.unitsInStore = 0;
	  this.productdiscription = productdiscription;	  
}	
  public int getProductnumber(){
	  return productnumber;
	  
  }
  public String getProductname(){
	  return productname;
  }
  public float getPrice(){
	  return price;
  }
  public int getOrderpoint(){
	  return orderpoint;
  }
  public int getUnitsInStore(){
	  return unitsInStore;
  }
  public String getProductdiscription(){
	  return productdiscription;
  }
  public void setProductnumber(int newProductnumber){
	  productnumber = newProductnumber;
  }
  public void setProductname(String newProductname){
	  productname = newProductname;
  }
  public void setPrice(float newPrice){
	  price = newPrice;
}
  public void setOrderpoint(int newOrderpoint){
	  orderpoint = newOrderpoint;
  }
  public void setUnitsInStore(int newUnitsInStore){
	  unitsInStore = newUnitsInStore;
  }
  public int iteminstore(){
	  
	  return unitsInStore;
	  
  }
   public void deliverance(){
	int deliverance;
	for(int i = 0; i < deliverance .length; i++){
		   deliverance ++;
		   
	   }
	  
  }
  public int withdrawCalculation(int product){
	 if (product < unitsInStore){
		 return -1;
	 }else{
		 unitsInStore-=product;
		 return 0;
	 }
		 
  }
}



I tried to write my code.But still i have error and i am not sure it is right or wrong. Please give me feed back.
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: Representing a product that small company sells.

Posted 20 November 2012 - 06:45 AM

You made good progress.

When you get errors you want help with, post them, copied and pasted from exactly as they appear on your end. Post errors in code tags too.

How are you testing your class? I don't see a main() method or a test program.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1