×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Implement Stock Item and Crypto Coin in Java Assignment Solution

June 25, 2024
Jessica Miller
Jessica Miller
🇺🇸 United States
Java
Jessica Miller is a seasoned programmer with a master's degree in software engineering from Stanford University. Having completed over 700 Java assignments, Jessica excels in implementing sorting algorithms, multi-dimensional arrays, and efficient array operations. Her deep understanding of complex programming concepts and hands-on experience make her a valuable resource for students seeking high-quality homework help.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Use Python libraries effectively by importing only what you need. For example, if you're working with data, using libraries like pandas and numpy can save time and simplify complex tasks like data manipulation and analysis.
News
In 2024, the Biden-Harris Administration has expanded high-dosage tutoring and extended learning programs to boost academic achievement, helping programming students and others recover from pandemic-related setbacks. These initiatives are funded by federal resources aimed at improving math and literacy skills​

Instructions

Objective

Write a java homework to implement stock item and crypto coin.

Requirements and Specifications

Program-to-implement-stock-item-and-crypto-coin-in-java (1)

Source Code

CRYPTO COIN package Assignment; public class CryptoCoin extends StockItem { public CryptoCoin(String stockCode, int variableQuantity, double variablePrice) { super(stockCode, variableQuantity, variablePrice); } @Override public String getStockName() { return "C-Coin"; } @Override public String getStockDescription() { return "CryptoCoin"; } @Override public String toString() { return super.toString(); } } ELECTRIC CAR package Assignment; public class CryptoCoin extends StockItem { public CryptoCoin(String stockCode, int variableQuantity, double variablePrice) { super(stockCode, variableQuantity, variablePrice); } @Override public String getStockName() { return "C-Coin"; } @Override public String getStockDescription() { return "CryptoCoin"; } @Override public String toString() { return super.toString(); } } MOBILE TABLET package Assignment; public class MobileTablet extends StockItem { public MobileTablet(String stockCode, int variableQuantity, double variablePrice) { super(stockCode, variableQuantity, variablePrice); } @Override public String getStockName() { return "MPad"; } @Override public String getStockDescription() { return "Mobile Tablet"; } @Override public String toString() { return super.toString(); } } NAV SYS package Assignment; public class NavSys extends StockItem { public NavSys(String stockCode, int variableQuantity, double variablePrice) { super(stockCode, variableQuantity, variablePrice); } @Override public String getStockName() { return "Navigation System"; } @Override public String getStockDescription() { return "GeoVision Sat Nav"; } @Override public String toString() { return super.toString(); } public static void main(String[] args) { int q = 10; double price = 99.99; String code = "NS101"; System.out.println("Creating a stock with " + q + " units Navigation system, price " + price + " each, and item " + code); System.out.println("Printing item stock information"); NavSys navSysItem = new NavSys(code, q, price); System.out.println(); System.out.println(navSysItem); int addedQ = 10; System.out.println("Increasing " + addedQ + " more units"); System.out.println("Printing item stock information"); navSysItem.addStock(addedQ); System.out.println(); System.out.println(navSysItem); int soldQ = 2; System.out.println("Sold " + soldQ + " units"); System.out.println("Printing item stock information"); navSysItem.sellStock(soldQ); System.out.println(); System.out.println(navSysItem); double newPrice = 100.99; System.out.println("Set new price " + newPrice + " per unit"); System.out.println("Printing item stock information"); navSysItem.setVariablePrice(newPrice); System.out.println(); System.out.println(navSysItem); addedQ = 0; System.out.println("Increasing " + addedQ + " more units"); System.out.println(); System.out.print("The error was: "); navSysItem.addStock(addedQ); } } STOCK ITEM package Assignment; public class StockItem { private static final double VAT_RATE = 0.175; private String stockCode; private int variableQuantity; private double variablePrice; public StockItem(String stockCode, int variableQuantity, double variablePrice) { this.stockCode = stockCode; this.variableQuantity = variableQuantity; this.variablePrice = variablePrice; } public String getStockName() { return "Unknown Stock Name"; } public String getStockDescription() { return "Unknown Stock Description"; } public String getStockCode() { return stockCode; } public void setStockCode(String stockCode) { this.stockCode = stockCode; } public int getVariableQuantity() { return variableQuantity; } public void setVariableQuantity(int variableQuantity) { this.variableQuantity = variableQuantity; } public double getVariablePrice() { return variablePrice; } public void setVariablePrice(double variablePrice) { this.variablePrice = variablePrice; } public double getPriceWithVAT() { return variablePrice * (1 + VAT_RATE); } public boolean addStock(int q) { if (q < 1) { System.out.println("Increased item must be greater thanor equal to one"); return false; } if (variableQuantity + q > 100) { System.out.println("Stock quantity exceeds 100"); return false; } variableQuantity += q; return true; } public boolean sellStock(int q) { if (q < 1) { System.out.println("Sold amount must be positive"); return false; } if (variableQuantity < q) { return false; } variableQuantity -= q; return false; } @Override public String toString() { return "Stock Type: " + getStockName() + System.lineSeparator() + "Description: " + getStockDescription() + System.lineSeparator() + "StockCode: " + getStockCode() + System.lineSeparator() + "PriceWithoutVAT: " + getVariablePrice() + System.lineSeparator() + "PriceWithVAT: " + getPriceWithVAT() + System.lineSeparator() + "Total units in stock: " + getVariableQuantity() + System.lineSeparator(); } public static void main(String[] args) { int q = 10; double price = 99.99; String code = "W101"; System.out.println("Creating a stock with " + q + " units Unknown item, price " + price + " each, and item " + code); System.out.println("Printing item stock information"); StockItem stockItem = new StockItem(code, q, price); System.out.println(); System.out.println(stockItem); int addedQ = 10; System.out.println("Increasing " + addedQ + " more units"); System.out.println("Printing item stock information"); stockItem.addStock(addedQ); System.out.println(); System.out.println(stockItem); int soldQ = 2; System.out.println("Sold " + soldQ + " units"); System.out.println("Printing item stock information"); stockItem.sellStock(soldQ); System.out.println(); System.out.println(stockItem); double newPrice = 100.99; System.out.println("Set new price " + newPrice + " per unit"); System.out.println("Printing item stock information"); stockItem.setVariablePrice(newPrice); System.out.println(); System.out.println(stockItem); addedQ = 0; System.out.println("Increasing " + addedQ + " more units"); System.out.println(); System.out.print("The error was: "); stockItem.addStock(addedQ); } } TEST POLYMORPHISM package Assignment; public class TestPolymorphism { public static void main(String[] args) { int q = 10; double price = 99.99; String code = "W101"; System.out.println("Creating a stock with " + q + " units Unknown item, price " + price + " each, and item " + code); StockItem stockItem = new StockItem(code, q, price); itemInstance(stockItem); System.out.println(); q = 10; price = 99.99; code = "NS101"; System.out.println("Creating a stock with " + q + " units Navigation item, price " + price + " each, and item " + code); NavSys navSys = new NavSys(code, q, price); itemInstance(navSys); System.out.println(); q = 10; price = 129.99; code = "EC101"; System.out.println("Creating a stock with " + q + " units ECar item, price " + price + " each, and item " + code); ElectricCar eCar = new ElectricCar(code, q, price); itemInstance(eCar); System.out.println(); q = 10; price = 129.99; code = "MP101"; System.out.println("Creating a stock with " + q + " units MPad item, price " + price + " each, and item " + code); MobileTablet mPad = new MobileTablet(code, q, price); itemInstance(mPad); q = 10; price = 149.99; code = "CC101"; System.out.println("Creating a stock with " + q + " units CCoin item, price " + price + " each, and item " + code); CryptoCoin cCoin = new CryptoCoin(code, q, price); itemInstance(cCoin); } public static void itemInstance(StockItem stockItem) { System.out.println("Printing item stock information"); System.out.println(); System.out.println(stockItem); int addedQ = 10; System.out.println("Increasing " + addedQ + " more units"); System.out.println("Printing item stock information"); stockItem.addStock(addedQ); System.out.println(); System.out.println(stockItem); int soldQ = 2; System.out.println("Sold " + soldQ + " units"); System.out.println("Printing item stock information"); stockItem.sellStock(soldQ); System.out.println(); System.out.println(stockItem); double newPrice = 100.99; System.out.println("Set new price " + newPrice + " per unit"); System.out.println("Printing item stock information"); stockItem.setVariablePrice(newPrice); System.out.println(); System.out.println(stockItem); addedQ = 0; System.out.println("Increasing " + addedQ + " more units"); System.out.println(); System.out.print("The error was: "); stockItem.addStock(addedQ); } }

Similar Samples

Explore our curated collection of programming homework samples at ProgrammingHomeworkHelp.com. Covering Java, Python, C++, and more, our samples showcase expertise in solving diverse coding challenges. Each example demonstrates clarity, precision, and adherence to academic standards. Dive into our samples to see how we can assist you in mastering programming concepts and achieving top grades.