-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTenderEvaluationSystem.java
More file actions
77 lines (62 loc) · 2.75 KB
/
Copy pathTenderEvaluationSystem.java
File metadata and controls
77 lines (62 loc) · 2.75 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
import java.util.Scanner;
// 1. The Tender Class
class Tender {
private double quotation;
private String companyName;
// Parameterized constructor
public Tender(double quotation, String companyName) {
this.quotation = quotation;
this.companyName = companyName;
}
// Getters to maintain Encapsulation
public double getQuotation() {
return quotation;
}
public String getCompanyName() {
return companyName;
}
}
// 2. The Main Driver Class (PascalCase)
public class TenderEvaluationSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Array of objects to store exactly 5 Tender instances
Tender[] tenders = new Tender[5];
System.out.println("--- Tender Application System ---");
// Loop 1: Accepting data for 5 objects
for (int i = 0; i < tenders.length; i++) {
System.out.println("\nEntering details for Company " + (i + 1) + ":");
System.out.print("Enter Company Name: ");
String name = scanner.nextLine();
System.out.print("Enter Quotation Amount: ");
double amount = getValidDouble(scanner);
scanner.nextLine(); // Consume the leftover newline character
// Initialize the object directly into the array
tenders[i] = new Tender(amount, name);
}
// Loop 2: Finding the company with the minimum quotation
int minIndex = 0;
for (int i = 1; i < tenders.length; i++) {
// Compare the current quotation with the lowest one found so far
if (tenders[i].getQuotation() < tenders[minIndex].getQuotation()) {
minIndex = i;
}
}
// Displaying the final result
System.out.println("\n=========================================");
System.out.println(" TENDER ALLOCATION RESULT ");
System.out.println("=========================================");
System.out.println("Winning Company: " + tenders[minIndex].getCompanyName());
System.out.println("Minimum Quotation: " + tenders[minIndex].getQuotation());
System.out.println("=========================================");
scanner.close();
}
// Helper method to prevent the Scanner from crashing if a user types letters instead of numbers
private static double getValidDouble(Scanner scanner) {
while (!scanner.hasNextDouble()) {
System.out.print("Invalid input. Please enter a valid numerical amount: ");
scanner.next(); // Consume the invalid input
}
return scanner.nextDouble();
}
}