Question

In: Computer Science

to be done in java Your task is to finish the StockItem class so that it...

to be done in java

Your task is to finish the StockItem class so that it meets the following criteria

• The StockItem class will have 4 attributes:

a stock number;

a name;

the price of the item;

the total number of items currently in stock

• The first three of the above characteristics will need to be set at the time a StockItem object is created, with the total number of items set to 0 at this time. The stock number and name will not need to be changed after an item is created.

• The following methods are also required:

o A method that allows the price to be re-set during the object's lifetime

o a method that takes an integer argument and adds this to the total number of items in stock

o a method that returns the total value of items of this stock type;

calculated by multiplying the price of the item by the number of items in stock (price * units)

Required Methods: StockItem(String, String, double) (class constructor) setPrice(double) increaseTotalStock(int) getStockNumber(): String getName(): String getTotalStock(): int getPrice(): double calculateTotalPrice(): double

Requested files StockItem.java

/** * A class representing an item in stock in some sort * of inventory system */

public class StockItem {

//TODO: add fields for a: name, stockNumber, price, units.

//TODO: create a constructor that takes name, stockNumber and price as arguments

// and sets units to 0.

//TODO: create accessor ("getter") methods for price, stock number and name.

//TODO: create a method increaseTotalStock that increases units by a given quantity.

//TODO:create a mutator ("setter") method setPrice that sets price to a given amount.

//TODO: create a method calculateTotalPrice that returns the total price of the current inventory

// (Calculated as current price * number of units) }

Solutions

Expert Solution

Code is Given Below:

-----------------------------------

public class StockItem {
   private String stockNumber;
   private String name;
   private double price;//the price of the item;
   private int totalNumber;//the total number of items currently in stock
   //constructor that takes name, stockNumber and price as arguments
   public StockItem(String stockNumber, String name, double price) {
       this.stockNumber = stockNumber;
       this.name = name;
       this.price = price;
       this.totalNumber=0;
   }
  
   public void setPrice(double price) {
       this.price=price;
      
   }
   // method increaseTotalStock that increases units by a given quantity.
   public void increaseTotalStock(int n) {
       totalNumber=totalNumber+n;
   }
   //accessor ("getter") methods for price, stock number and name.
   public String getStockNumber() {
       return stockNumber;
   }
   public String getName() {
       return name;
   }
   public int getTotalStock() {
       return totalNumber;
   }
   public double getPrice() {
       return price;
   }
   //method calculateTotalPrice that returns the total price of the current inventory
   public double calculateTotalPrice() {
       return price*totalNumber;
   }
  
}

Code Snapshot:

-----------------------------


Related Solutions

JAVA PROGRAM: FINISH THE FOLLOWING METHOD IN THE CLASS BasicBioinformatics. public class BasicBioinformatics { /** *...
JAVA PROGRAM: FINISH THE FOLLOWING METHOD IN THE CLASS BasicBioinformatics. public class BasicBioinformatics { /** * Calculates and returns the reverse complement of a DNA sequence. In DNA sequences, 'A' and 'T' * are complements of each other, as are 'C' and 'G'. The reverse complement is formed by * reversing the symbols of a sequence, then taking the complement of each symbol (e.g., the * reverse complement of "GTCA" is "TGAC"). * * @param dna a char array representing...
Use BlueJ java to finish this PolkaDots class, class circle is included below as well. public...
Use BlueJ java to finish this PolkaDots class, class circle is included below as well. public class PolkaDots { private ArrayList<Circle> dots;// an arrayList field to hold an ArrayList. /** * Create a new list of Circles, starts with 5 default circles. */ public PolkaDots() { dots = new ArrayList<Circle>(); // an arrayList to hold a bunch of circles Circle circle1 = new Circle(30, 10, 10, "blue");//create the 1st circle dots.add(circle1);// add the 1st circle to the arrayList    Circle...
TO BE DONE IN JAvA Complete the calculator program so that it prompts the user to...
TO BE DONE IN JAvA Complete the calculator program so that it prompts the user to enter two integers and an operation and then outputs the answer. Prompt the user three times, don't expect all the inputs on one line. Possible operations are + - * / No other words or symbols should be output, just the answer. Requested files import java.util.Scanner; /** * This is a simple calculator Java program. * It can be used to calculate some simple...
I need this done in JAVA. Define a class named Cash. The class contains the following...
I need this done in JAVA. Define a class named Cash. The class contains the following public elements: A Double stored property that contains the amount of money (dollars and cents) described by an object of the class. A read-only, computed property. It calculates and returns the minimum number of U.S. bills and coins that add up to the amount in the stored property.  The return value is an Int array of length 9 that contains (beginning with index 0 of...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm:...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase and lowercase) converted to its successor except z and Z, which are converted to 'a' and 'A' respectively (i.e., a to b, b to c, …, y to z, z to a, A to B, B to C, …, Y to Z, Z to A) Every digit converted to its predecessor except 0, which is converted to 9 (i.e., 9...
Please finish the following JAVA Codes: 1. The class Person includes information of a person’s first...
Please finish the following JAVA Codes: 1. The class Person includes information of a person’s first name, last name, phone number, and email. Implement the class with appropriate constructors, getters and setters. 2. Derive a Student class that extends Person. In addition to a person’s information, a student has major, year, GPA, and a list of enrolled courses. In addition to appropriate constructors, getters and setters, make two methods addCourse and dropCourse. 3. Design and implement a program, either in...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
JAVA the task is to implement the missing methods in the LinkedIntSet class. Each method you...
JAVA the task is to implement the missing methods in the LinkedIntSet class. Each method you must write has comments describing how it should behave. You may not add any new fields to the LinkedIntSet class and you may only add new code inside the bodies of the 5 methods you are asked to write. You may also write new private helper methods. However, you may not change any method headers, you may not change any code outside of the...
To be done in Java Consider the partially complete book class given.    Make the following...
To be done in Java Consider the partially complete book class given.    Make the following additions to the book class. Add a getAuthor() and a getTitle() method to the book class. They should take no parameters and should return a String. Change the 3-parameter constructor for the class so that it correctly initializes the member variables. Write an accessor method called getPages(). Add a zero parameter getDetails() method to the Book class. It should assemble the information for a...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT