Question

in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...

in jGRASP

INVENTORY CLASS

You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object).

Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object).

The data fields in the Inventory class include the inventory product number (int), inventory product description (String), inventory product price (float), inventory quantity on hand (int), inventory quantity on order (int), and inventory quantity sold (int).

The Inventory class (.java file) should also contain all of the static data fields, as well as static methods to handle the logic in counting all of the objects processed (counter), as well as totals (accumulators) for the total product inventory and the total product inventory dollar value.

Your Inventory class .java should also contain all of the methods in order to calculate the current product inventory and the dollar value of the inventory product, as well as handling inventory product levels.

In order to calculate the current product inventory, the formula is inventory quantity on hand plus inventory quantity on order minus inventory quantity sold. In order to calculate the dollar value of the inventory product, the formula is inventory product price * (inventory quantity on hand + inventory quantity on order – inventory quantity sold).   

A message should be generated and displayed to the user when the inventory product should be ordered if the current product inventory is less than 50 products. For data type float, show the output precision to two decimal places.

The Inventory class should not contain any computer programming code related to inputting of the data or outputting or displaying of the information for this should be handled by the GUI (Graphical User Interface). No GUI programming code should be contained in the Inventory class (.java) file.

General Format of a User-Defined Class

private data fields

final static constants (rates for example)

static programmer-defined variables for counters/accumulators

one or more constructors (overloaded constructors also)

mutator and accessor methods for the private data fields

overloaded mutators to handle data coming into the class in a different data type

methods to calculate and any other methods necessary

methods to add/return for counter(s)

methods to add/return for accumulator(s)

may also want to add the toString method to the Inventory class to show the objects contents.

The Inventory class (.java file) must be a separate .java file from the GUI .java file(s).

public class Inventory {
private int productNumber;
private String productDescription;
private double productPrice;
private int quantityOnHand;
private int quantityOnOrder;
private int quantitySold;
private static int counter;

/**
* @param productNumber
* @param productDescription
* @param productPrice
* @param quantityOnHand
* @param quantityOnOrder
* @param quantitySold
*/



public Inventory(int productNumber, String productDescription,
double productPrice, int quantityOnHand, int quantityOnOrder,
int quantitySold) {
this.productNumber = productNumber;
this.productDescription = productDescription;
this.productPrice = productPrice;
this.quantityOnHand = quantityOnHand;
this.quantityOnOrder = quantityOnOrder;
this.quantitySold = quantitySold;
counter++;
}
public class Test {

public static void main(String[] args) {

Inventory i1=new Inventory(1111,"Laptops",1200,340,100,200);
Inventory i2=new Inventory(1213,"Mobile",350,100,50,30);
System.out.println("No of "+i1.getProductDescription()+" in Inventory :"+i1.currentProductInventory());
System.out.println("Total Cost of "+i1.getProductDescription()+" in Inventory :"+i1.currentProductInventoryValue());
System.out.println("No of "+i2.getProductDescription()+" in Inventory :"+i2.currentProductInventory());
System.out.println("Total Cost of "+i2.getProductDescription()+" in Inventory :"+i2.currentProductInventoryValue());
System.out.println("No of Product Types in Inventory :"+Inventory.totNoofProductsInInventory());
  
  
  

}

}


/**
* @return the productNumber
*/
public int getProductNumber() {
return productNumber;
}

/**
* @param productNumber
* the productNumber to set
*/
public void setProductNumber(int productNumber) {
this.productNumber = productNumber;
}

/**
* @return the productDescription
*/
public String getProductDescription() {
return productDescription;
}

/**
* @param productDescription
* the productDescription to set
*/
public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}

/**
* @return the productPrice
*/
public double getProductPrice() {
return productPrice;
}

/**
* @param productPrice
* the productPrice to set
*/
public void setProductPrice(double productPrice) {
this.productPrice = productPrice;
}

/**
* @return the quantityOnHand
*/
public int getQuantityOnHand() {
return quantityOnHand;
}

/**
* @param quantityOnHand
* the quantityOnHand to set
*/
public void setQuantityOnHand(int quantityOnHand) {
this.quantityOnHand = quantityOnHand;
}

/**
* @return the quantityOnOrder
*/
public int getQuantityOnOrder() {
return quantityOnOrder;
}

/**
* @param quantityOnOrder
* the quantityOnOrder to set
*/
public void setQuantityOnOrder(int quantityOnOrder) {
this.quantityOnOrder = quantityOnOrder;
}

/**
* @return the quantitySold
*/
public int getQuantitySold() {
return quantitySold;
}

/**
* @param quantitySold
* the quantitySold to set
*/
public void setQuantitySold(int quantitySold) {
this.quantitySold = quantitySold;
}

public int currentProductInventory() {
return (quantityOnHand + quantityOnOrder) - quantitySold;
}

public static int totNoofProductsInInventory()
{
return counter;
}
public double currentProductInventoryValue() {
return ((quantityOnHand + quantityOnOrder) - quantitySold)
* productPrice;
}

public void CheckToOrderInventory()
{
if(currentProductInventory()<50)
{
System.out.println("You have to Order Inventory");
}
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Inventory [productNumber=" + productNumber
+ ", productDescription=" + productDescription
+ ", productPrice=" + productPrice + ", quantityOnHand="
+ quantityOnHand + ", quantityOnOrder=" + quantityOnOrder
+ ", quantitySold=" + quantitySold + "]";
}
  
}

Homework Answers

Answer #1
public class Test {

   public static void main(String[] args) {

       Inventory i1=new Inventory(1111,"Laptops",1200,340,100,200);
       Inventory i2=new Inventory(1213,"Mobile",350,100,50,30);
       System.out.println("No of "+i1.getProductDescription()+" in Inventory :"+i1.currentProductInventory());
       System.out.println("Total Cost of "+i1.getProductDescription()+" in Inventory :"+i1.currentProductInventoryValue());
       System.out.println("No of "+i2.getProductDescription()+" in Inventory :"+i2.currentProductInventory());
       System.out.println("Total Cost of "+i2.getProductDescription()+" in Inventory :"+i2.currentProductInventoryValue());
       System.out.println("No of Product Types in Inventory :"+Inventory.totNoofProductsInInventory());
      
      
      

   }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In Java Let’s say we’re designing a Student class that has two data fields. One data...
In Java Let’s say we’re designing a Student class that has two data fields. One data field, called id, is for storing each student’s ID number. Another data field, called numStudents, keeps track of how many Student objects have been created. For each of the blanks, indicate the appropriate choice. id should be   public/private   and   static/not static . numStudents should be   public/private   and   static/not static . The next three questions use the following class: class Counter {     private int...
Which method is correct to access the value of count? public class Person { private String...
Which method is correct to access the value of count? public class Person { private String name; private int age; private static int count = 0; } A. private int getCount() {return (static)count;} B. public static int getCount() {return count;} C. public int getCount() {return static count;} D. private static int getCount() {return count;} How can you print the value of count? public class Person { private String name; private int age; private static int count=0; public Person(String a, int...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
public class Date {    private int month;    private int day;    private int year;...
public class Date {    private int month;    private int day;    private int year;    public Date( int monthValue, int dayValue, int yearValue )    {       month = monthValue;       day = dayValue;       year = yearValue;    }    public void setMonth( int monthValue )    {       month = monthValue;    }    public int getMonth()    {       return month;    }    public void setDay( int dayValue )    {       day =...
Hello. I have an assignment that is completed minus one thing, I can't get the resize...
Hello. I have an assignment that is completed minus one thing, I can't get the resize method in Circle class to actually resize the circle in my TestCircle claass. Can someone look and fix it? I would appreciate it! If you dont mind leaving acomment either in the answer or just // in the code on what I'm doing wrong to cause it to not work. That's all I've got. Just a simple revision and edit to make the resize...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Write a pseudocode for the following java programs: public class Item {    private String name;...
Write a pseudocode for the following java programs: public class Item {    private String name;    private double cost;    public Item(String name, double cost) {        this.name = name;        this.cost = cost;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getCost() {        return cost;    }    public void setCost(double cost) {...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...