0% found this document useful (0 votes)
8 views6 pages

saol 4

jawaban soal sistem berbasis data 4

Uploaded by

Fajar Arip Usba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

saol 4

jawaban soal sistem berbasis data 4

Uploaded by

Fajar Arip Usba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

import java.util.

ArrayList;

import java.util.Scanner;

public class InventoryManagementSystem {

private ArrayList<Item> inventory;

private Scanner scanner;

public InventoryManagementSystem() {

inventory = new ArrayList<>();

scanner = new Scanner(System.in);

public void addItem() {

System.out.print("Enter item name: ");

String name = scanner.nextLine();

System.out.print("Enter item quantity: ");

int quantity = scanner.nextInt();

Item item = new Item(name, quantity);

inventory.add(item);

public void removeItem() {

System.out.print("Enter item name: ");

String name = scanner.nextLine();

for (Item item : inventory) {

if (item.getName().equals(name)) {

inventory.remove(item);

break;
}

public void displayInventory() {

for (Item item : inventory) {

System.out.println(item.getName() + " - " + item.getQuantity());

public static void main(String[] args) {

InventoryManagementSystem system = new InventoryManagementSystem();

while (true) {

System.out.println("1. Add item");

System.out.println("2. Remove item");

System.out.println("3. Display inventory");

System.out.print("Enter choice: ");

int choice = scanner.nextInt();

switch (choice) {

case 1:

system.addItem();

break;

case 2:

system.removeItem();

break;

case 3:

system.displayInventory();

break;
default:

System.out.println("Invalid choice");

class Item {

private String name;

private int quantity;

public Item(String name, int quantity) {

this.name = name;

this.quantity = quantity;

public String getName() {

return name;

public int getQuantity() {

return quantity;

}import java.util.ArrayList;

import java.util.Scanner;

public class InventoryManagementSystem {

private ArrayList<Item> inventory;


private Scanner scanner;

public InventoryManagementSystem() {

inventory = new ArrayList<>();

scanner = new Scanner(System.in);

public void addItem() {

System.out.print("Enter item name: ");

String name = scanner.nextLine();

System.out.print("Enter item quantity: ");

int quantity = scanner.nextInt();

Item item = new Item(name, quantity);

inventory.add(item);

public void removeItem() {

System.out.print("Enter item name: ");

String name = scanner.nextLine();

for (Item item : inventory) {

if (item.getName().equals(name)) {

inventory.remove(item);

break;

public void displayInventory() {


for (Item item : inventory) {

System.out.println(item.getName() + " - " + item.getQuantity());

public static void main(String[] args) {

InventoryManagementSystem system = new InventoryManagementSystem();

while (true) {

System.out.println("1. Add item");

System.out.println("2. Remove item");

System.out.println("3. Display inventory");

System.out.print("Enter choice: ");

int choice = scanner.nextInt();

switch (choice) {

case 1:

system.addItem();

break;

case 2:

system.removeItem();

break;

case 3:

system.displayInventory();

break;

default:

System.out.println("Invalid choice");

}
}

class Item {

private String name;

private int quantity;

public Item(String name, int quantity) {

this.name = name;

this.quantity = quantity;

public String getName() {

return name;

public int getQuantity() {

return quantity;

You might also like