Last active
January 19, 2023 21:58
-
-
Save sedj601/62bb51b8e16f8bebd582b1c475ae0aae to your computer and use it in GitHub Desktop.
StackOverflow Help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Inventory { | |
private String id; | |
private String description; | |
private boolean stock_status; | |
private double item_price; | |
public Inventory(String id, String description, boolean stock_status, double item_price) { | |
this.id = id; | |
this.description = description; | |
this.stock_status = stock_status; | |
this.item_price = item_price; | |
} | |
public String getId() { | |
return id; | |
} | |
public void setId(String id) { | |
this.id = id; | |
} | |
public String getDescription() { | |
return description; | |
} | |
public void setDescription(String description) { | |
this.description = description; | |
} | |
public boolean getStock_status() { | |
return stock_status; | |
} | |
public void setStock_status(boolean stock_status) { | |
this.stock_status = stock_status; | |
} | |
public double getItem_price() { | |
return item_price; | |
} | |
public void setItem_price(double item_price) { | |
this.item_price = item_price; | |
} | |
@Override | |
public String toString() { | |
StringBuilder sb = new StringBuilder(); | |
sb.append("Inventory{"); | |
sb.append("id=").append(id); | |
sb.append(", description=").append(description); | |
sb.append(", stock_status=").append(stock_status); | |
sb.append(", item_price=").append(item_price); | |
sb.append('}'); | |
return sb.toString(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.Control; | |
import javafx.scene.control.TextField; | |
import javafx.scene.layout.HBox; | |
import javafx.scene.layout.StackPane; | |
import javafx.stage.Stage; | |
public class App extends Application { | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage stage) throws Exception { | |
TextField tfId = new TextField(); | |
Button btnCheckStatus = new Button("Check Status"); | |
btnCheckStatus.setOnAction((t) -> { | |
CheckItemStatus(tfId, getInventory()); | |
}); | |
HBox hBox = new HBox(tfId, btnCheckStatus); | |
hBox.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE); | |
Scene scene = new Scene(new StackPane(hBox), 800, 300); | |
stage.setScene(scene); | |
stage.show(); | |
} | |
//Get the inventory array! | |
public Inventory[] getInventory() | |
{ | |
Inventory[] inventoryArr = new Inventory[42]; | |
inventoryArr[0] = new Inventory("14", "Stanley #2 Philips Screwdriver", true, 6.95); | |
inventoryArr[1] = new Inventory("2342", "Polar USB mini desk fan", false, 10.50); | |
inventoryArr[2] = new Inventory("22389", "Swingline Model B2200 stapler", true, 18.00); | |
inventoryArr[3] = new Inventory("3451", "Oakley Jawbreaker sunglasses", true, 236.00); | |
inventoryArr[4] = new Inventory("4452", "Colnago stem - black 130mm", false, 145.99); | |
inventoryArr[5] = new Inventory("56718", "Tamiya Mclaren MP4-8 Ford 1/20", false, 75.00); | |
inventoryArr[6] = new Inventory("14909", "1/4in - 28tpi SS nuts", true, 1.00); | |
inventoryArr[7] = new Inventory("2190", "Hefty 30 gal with handles - box 40", true, 19.00); | |
inventoryArr[8] = new Inventory("22345532", "3 ft mini USB cable M-F", true, 4.50); | |
inventoryArr[9] = new Inventory("678944", "EZ-ink cartrige set for Epson 4630", false, 75.00); | |
inventoryArr[10] = new Inventory("234887", "2021 CSX train calendar", true, 12.95); | |
inventoryArr[11] = new Inventory("198", "Box of 10 Sharpie Roller 0.5mm", true, 6.50); | |
inventoryArr[12] = new Inventory("298765", "3x5 index cards - 100 count", true, 2.25); | |
inventoryArr[13] = new Inventory("7654", "Bell Stratos helmet - size Lg - blue", false, 230.00); | |
inventoryArr[14] = new Inventory("67YX22", "DTM Calendar for 2023", false, 14.95); | |
inventoryArr[15] = new Inventory("65435689", "12x16 paper cutter with ruler", true, 35.95); | |
inventoryArr[16] = new Inventory("8543", "Ritchey 1 inch threaded headset - silver", true, 45.00); | |
inventoryArr[17] = new Inventory("38712987", "Wilson NCAA official softball - 1 ea", true, 5.50); | |
inventoryArr[18] = new Inventory("2234983", "Wilson NCAA official softball - 1 doz", true, 55.00); | |
inventoryArr[19] = new Inventory("23", "Tamiya 2oz paint - ferrari red", true, 2.39); | |
inventoryArr[20] = new Inventory("97634", "Campagnolo 12 spd crankset - 53/39 175mm", true, 750.00); | |
inventoryArr[21] = new Inventory("85456", "Campagnolo 12 spd rear der", true, 350.00); | |
inventoryArr[22] = new Inventory("67913", "Gios Torino t-shirt size XXL", true, 25.00); | |
inventoryArr[23] = new Inventory("387", "Brachs butterscotch hard candy - 1 lb", true, 4.50); | |
inventoryArr[24] = new Inventory("113355", "The Bourne Identity - blu-ray", true, 15.95); | |
inventoryArr[25] = new Inventory("1111", "Top Secret Twenty One - Janet Evanovich", true, 8.99); | |
inventoryArr[26] = new Inventory("286934", "1 lb - coffee beans", true, 6.50); | |
inventoryArr[27] = new Inventory("358922", "25 lbs peanuts in shell", false, 45.00); | |
inventoryArr[28] = new Inventory("47831", "8x10 picture frame", true, 4.95); | |
inventoryArr[29] = new Inventory("19981", "Pledge furniture polish 13oz", true, 6.50); | |
inventoryArr[30] = new Inventory("228865", "3M Super 33+ electrical tape", true, 3.50); | |
inventoryArr[31] = new Inventory("228865X", "3M Super 33+ electrical tape box 10", true, 32.50); | |
inventoryArr[32] = new Inventory("4762", "HP copy paper ultra white - ream", true, 13.50); | |
inventoryArr[33] = new Inventory("29741", "Plush teddy bear 8 inch", true, 24.00); | |
inventoryArr[34] = new Inventory("339921", "Yamaha KT 100 kart engine", true, 950.00); | |
inventoryArr[35] = new Inventory("115693", "Colnago C64 - Mapei frame", true, 6500.00); | |
inventoryArr[36] = new Inventory("582913", "Look Keo 2 Max pedals", true, 135.00); | |
inventoryArr[37] = new Inventory("4499120", "M&Ms dark chocolate w/peanuts - 3oz", true, 2.50); | |
inventoryArr[38] = new Inventory("268", "Sidi Wire 2 carbon shoes", true, 499.99); | |
inventoryArr[39] = new Inventory("89476", "Assos T-Evo shorts", true, 299.95); | |
inventoryArr[40] = new Inventory("245667", "Colnago jersey - size 6", true, 120.00); | |
inventoryArr[41] = new Inventory("RTX3452", "Laser Pointer", true, 38.80); | |
return inventoryArr; | |
} | |
//Check Item status! | |
public void CheckItemStatus(TextField input, Inventory[] invArr) | |
{ | |
int itemFoundIndex = findItem(input, invArr); | |
if(itemFoundIndex == -1) | |
{ | |
System.out.println("ID " + input.getText() + " was not found!"); | |
} | |
else | |
{ | |
if(!invArr[itemFoundIndex].getStock_status()) | |
{ | |
System.out.println("ID " + input.getText() + " is not in stock!"); | |
} | |
else | |
{ | |
System.out.println("ID " + input.getText() + " is in stock!"); | |
} | |
} | |
} | |
//Return the index of the item found and -1 if no item was found! | |
public static int findItem(TextField input, Inventory[] invArr) | |
{ | |
for (int i = 0; i < invArr.length; i++) { | |
if(input.getText().equals(invArr[i].getId())) | |
{ | |
return i; | |
} | |
} | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment