-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
145 lines (106 loc) · 3.45 KB
/
Copy pathMain.java
File metadata and controls
145 lines (106 loc) · 3.45 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.util.*;
class Bidder {
String name;
int bid;
Bidder(String name, int bid) {
this.name = name;
this.bid = bid;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Bidder> bidders = new ArrayList<>();
Random random = new Random();
String[] wishes = {
"Congratulations on winning!",
"Great bidding! Enjoy your product.",
"You are the highest bidder!",
"Auction completed successfully!",
"Excellent choice and winning bid!"
};
System.out.println("===== ONLINE AUCTION SYSTEM =====");
System.out.print("Enter Product Name: ");
String product = sc.nextLine();
System.out.print("Enter Starting Price: ₹");
int startPrice = sc.nextInt();
System.out.print("How many persons are ready to bid? ");
int n = sc.nextInt();
sc.nextLine();
// Initial bidders
for (int i = 1; i <= n; i++) {
System.out.println("\nPerson " + i);
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Bid Amount: ₹");
int bid = sc.nextInt();
sc.nextLine();
if (bid < startPrice) {
System.out.println(
"Bid should be at least ₹"
+ startPrice);
i--;
continue;
}
bidders.add(
new Bidder(name, bid)
);
}
// Additional bidders
while (true) {
System.out.print(
"\nAnyone else interested? (yes/no): ");
String choice =
sc.nextLine();
if (choice.equalsIgnoreCase("no")) {
break;
}
System.out.print(
"Enter Name: ");
String name =
sc.nextLine();
System.out.print(
"Enter Bid Amount: ₹");
int bid =
sc.nextInt();
sc.nextLine();
if (bid < startPrice) {
System.out.println(
"Bid rejected.");
continue;
}
bidders.add(
new Bidder(name, bid));
System.out.println(
"Bid Accepted");
}
// Find Winner
Bidder winner =
bidders.get(0);
for (Bidder b : bidders) {
if (b.bid >
winner.bid) {
winner = b;
}
}
System.out.println(
"\n===== AUCTION RESULT =====");
System.out.println(
"Product: " + product);
System.out.println(
"Winner: " +
winner.name);
System.out.println(
"Winning Bid: ₹" +
winner.bid);
System.out.println(
"\n" +
wishes[
random.nextInt(
wishes.length
)
]
);
sc.close();
}
}