-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockTradingPlatform.java
More file actions
63 lines (47 loc) · 1.74 KB
/
Copy pathStockTradingPlatform.java
File metadata and controls
63 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.Scanner;
class Stock {
String name;
double price;
Stock(String name, double price) {
this.name = name;
this.price = price;
}
}
public class StockTradingPlatform {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Stock[] stocks = {
new Stock("TCS", 3500),
new Stock("INFOSYS", 1800),
new Stock("RELIANCE", 2900)
};
System.out.println("========== STOCK MARKET ==========");
for (int i = 0; i < stocks.length; i++) {
System.out.println((i + 1) + ". " +
stocks[i].name + " - Rs." + stocks[i].price);
}
System.out.print("\nSelect a stock (1-" + stocks.length + "): ");
int choice = sc.nextInt();
if (choice < 1 || choice > stocks.length) {
System.out.println("Invalid stock selection.");
sc.close();
return;
}
Stock selected = stocks[choice - 1];
System.out.print("Enter quantity to buy: ");
int quantity = sc.nextInt();
if (quantity <= 0) {
System.out.println("Quantity must be greater than 0.");
sc.close();
return;
}
double total = quantity * selected.price;
System.out.println("\n========== PORTFOLIO ==========");
System.out.println("Stock : " + selected.name);
System.out.println("Price : Rs." + selected.price);
System.out.println("Quantity : " + quantity);
System.out.println("Investment : Rs." + total);
System.out.println("===============================");
sc.close();
}
}