Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions H071191007/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Item {
private int price;
private int quantity;
private String detail;
private String name;

public Item(int price, int quantity, String detail, String name) {
this.price = price;
this.quantity = quantity;
this.detail = detail;
this.name = name;
}
public void descItem() {
System.out.println(getPrice());
System.out.println(getQuantity());
System.out.println(getDetail());
System.out.println(getName());
}

public void setHarga(int price) {
this.price = price;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public void setDetail(String detail) {
this.detail = detail;
}
public void setName(String name) {
this.name = name;
}

public int getPrice() {
return this.price;
}

public int getQuantity() {
return this.quantity;
}

public String getDetail() {
return this.detail;
}
public String getName() {
return this.name;
}
}
174 changes: 174 additions & 0 deletions H071191007/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

class Main {
public static void main(String[] args) throws Exception {

Scanner sc = new Scanner(System.in);
System.out.println(" ITEM STORE ");
System.out.println(" ");

System.out.println("Masukkan Player Name (no space)");
String playerName = sc.next();
System.out.println("Masukkan Player Money");
double PlayerMoney = sc.nextDouble();
User player = new User(playerName, PlayerMoney);
player.setProduct(player.readProductList(
"D:\\VisualStudioCode\\Java\\Semester_2\\OOP_Class\\Lecture\\MidTest\\PlayerItem.txt"));

System.out.println("Masukkan StoreOwner Name (no space)");
String storeOwnerName = sc.next();
System.out.println("Masukkan StoreOwner Money");
double storeOwnerMoney = sc.nextDouble();
User storeOwner = new User();
System.out.println("adding store owner item...");
storeOwner.setProduct(storeOwner.readProductList(
"D:\\VisualStudioCode\\Java\\Semester_2\\OOP_Class\\Lecture\\MidTest\\StoreOwnerItem.txt"));
System.out.println("generating store...");
Store store = new Store(myStore);
System.out.println("adding store item...");
store.setProduct(store);
("D:\\VisualStudioCode\\Java\\Semester_2\\OOP_Class\\Lecture\\MidTest\\StoreItem.txt"));
System.out.println("all generate");

Integer count = 1;

Map<Integer, Item> playerItem = new HashMap<>();
for (Item pItem : player.getItemList()) {
playerItem.put(count, pItem);
count++;
}
Map<Integer, Item> storeOwnerItem = new HashMap<>();
for (Item soItem : storeOwner.getItemList()) {
storeOwnerItem.put(count, soItem);
count++;
}
Map<Integer, Item> storeItem = new HashMap<>();
for (Item sItem : store.getItems()) {
storeItem.put(count, sItem);
count++;
}

while (true) {
System.out.println("which role you want to use :");
System.out.println("0. stop\n1.player\n2. store owner\n");
switch (sc.nextInt()) {
case 0:
System.out.println("Exit..");
return;
case 1:
player.showStatus();
System.out.println("which action you want to use :");
System.out.println(
"1. buy from player\n2. buy from store\n3. sell from player\n4. sell from store\n");
switch (sc.nextInt()) {
case 1:
System.out.println("Item list");
storeOwner.showItem();
System.out.println("which item you want to buy");
int itemChoose1 = sc.nextInt();
System.out.println("how much you want to buy");
int amount1 = sc.nextInt();
player.buyFromUser(storeOwnerItem.get(itemChoose1),amount1 , storeOwner);

break;

case 2:
System.out.println("Item list");
store.myStore();
System.out.println("which item you want to buy");
int itemChoose2 = sc.nextInt();
System.out.println("how much you want to buy");
int amount2 = sc.nextInt();
player.buyFromUser(storeItem.get(itemChoose2),amount2 , storeOwner);

break;

case 3:
System.out.println("Item list");
player.showItem();
System.out.println("which item you want to sell");
int itemChoose3 = sc.nextInt();
System.out.println("how much you want to sell");
int amount3 = sc.nextInt();
player.sellToOwner(playerItem.get(itemChoose3),amount3, storeOwner);

break;

case 4:
System.out.println("Item list");
player.showItem();
System.out.println("which item you want to buy");
int itemChoose4 = sc.nextInt();
System.out.println("how much you want to buy");
int amount4 = sc.nextInt();
player.sellToStore(playerItem.get(itemChoose4),amount4, store);

break;

default:
break;
}
break;
case 2:
player.showStatus();
System.out.println("which action you want to use :");
System.out.println(
"1. buy from player\n2. buy from store\n3. sell from player\n4. sell from store\n");
switch (sc.nextInt()) {
case 1:
System.out.println("Item list");
storeOwner.showItem();
System.out.println("which item you want to buy");
int itemChoose1 = sc.nextInt();
System.out.println("how much you want to buy");
int amount1 = sc.nextInt();
storeOwner.buyFromUser(playerItem.get(itemChoose1),amount1 , player);

break;

case 2:
System.out.println("Item list");
store.myStore();
System.out.println("which item you want to buy");
int itemChoose2 = sc.nextInt();
System.out.println("how much you want to buy");
int amount2 = sc.nextInt();
storeOwner.buyFromStore(storeItem.get(itemChoose2),amount2 , store);

break;

case 3:
System.out.println("Item list");
player.showItem();
System.out.println("which item you want to sell");
int itemChoose3 = sc.nextInt();
System.out.println("how much you want to sell");
int amount3 = sc.nextInt();
storeOwner.sellToOwner(storeOwnerItem.get(itemChoose3),amount3, player);

break;

case 4:
System.out.println("Item list");
player.showItem();
System.out.println("which item you want to buy");
int itemChoose4 = sc.nextInt();
System.out.println("how much you want to buy");
int amount4 = sc.nextInt();
storeOwner.sellToStore(storeItem.get(itemChoose4),amount4, store);

break;

default:
break;
}
break;
default:
break;
}
}

}
}
1 change: 1 addition & 0 deletions H071191007/Player.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2;150;pen
66 changes: 66 additions & 0 deletions H071191007/Store.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import java.util.ArrayList;
import java.util.List;

class Store {
private User owner;
private List<Item> items;
private String name;
private int sell;
private int star;

public Store(User owner, List<Item> items, String name, int sell) {
this.owner = owner;
items = new ArrayList<>();
this.name = name;
this.sell = sell;
}
public User getOwner() {
return owner;
}
public String getName() {
return name;
}
public List<Item> getItems() {
return items;
}
public int getSell() {
return sell;
}
public int getStar() {
return star;
}
public void setOwner(User owner) {
this.owner = owner;
}
public void setName(String name) {
this.name = name;
}
public void setItems(List<Item> items) {
this.items = items;
}
public void setSell(int sell) {
this.sell = sell;
}
public void theStar() {
if (sell <= 1) {
star = 1;
} else if (sell <= 2) {
star = 2;
} else if (sell <= 3) {
star = 3;
}

public void myStore(){
ArrayList <Item> items = owner.getItemList();
System.out.println("-----------------------------");
System.out.println("\tMY STORE ");
System.out.println("-----------------------------");
System.out.println("Name : "+name);
System.out.println("Star : "+star);
System.out.println("-----------------------------");
for(int j=0;j<items.size();j++){
System.out.println( (j+1)+". "+items.get(j).getName()+"\n\tStok : "+items.get(j).getQuantity());
}
}

}
3 changes: 3 additions & 0 deletions H071191007/StoreItem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
12.00;40;shoes
1.00;130;bag
1;4;ex
3 changes: 3 additions & 0 deletions H071191007/StoreOwner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
12.00;4;candy
10.00;13;snack
12.33;10;detail
14 changes: 14 additions & 0 deletions H071191007/Tes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.nio.file.*;;
public class Tes {
public static String readFileAsString(String fileName)throws Exception {
String data = "";
data = new String(Files.readAllBytes(Paths.get(fileName)));
return data;
}

public static void main(String[] args) throws Exception
{
String data = readFileAsString("D:\\VisualStudioCode\\Java\\Semester_2\\OOP_Class\\Lecture\\MidTest\\text.txt");
System.out.println(data);
}
}
Loading