-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventory_Audit_Activity.java
More file actions
71 lines (54 loc) · 1.49 KB
/
Inventory_Audit_Activity.java
File metadata and controls
71 lines (54 loc) · 1.49 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
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class Inventory_Audit_Activity {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
File file = new File("inventory_audit.txt");
initFile(file);
System.out.print("How many items to audit? ");
int itemNo = sc.nextInt();
int[] items = inputStock(sc, itemNo);
for (int i = 0; i < items.length; i++) {
String data = String.format("Item %d: %d units - %s", (i + 1), items[i], checkStatus(items[i]));
System.out.println(data);
saveAudit(file, data);
}
System.out.println("Saved report to" + file.getName());
}
public static int[] inputStock(Scanner sc, int itemNo) {
int[] items = new int[itemNo];
for (int i = 0; i < items.length; i++) {
System.out.printf("Item %d: ", (i + 1));
items[i] = sc.nextInt();
}
return items;
}
public static String checkStatus(int quantity) {
if (quantity >= 500) {
return "Overstocked";
} else if (quantity >= 100) {
return "Healthy Stock";
} else {
return "Critical Low";
}
}
public static void initFile(File file) {
try {
if (!file.exists()) {
file.createNewFile();
}
} catch (Exception e) {
System.out.println("Something went wrong!");
}
}
public static void saveAudit(File file, String data) {
try {
FileWriter writer = new FileWriter(file, true);
writer.write(data + "\n");
writer.close();
} catch (Exception e) {
System.out.println("Something went wrong!");
}
}
}