-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedicineToJson.java
52 lines (36 loc) · 1.51 KB
/
medicineToJson.java
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
// writes medicine info to JSON
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import org.json.simple.JSONObject;
import java.util.Scanner;
public class medicineToJson
{
public static void main(String[] args) throws FileNotFoundException
{
// creating JSONObject
JSONObject jo = new JSONObject();
Scanner myScanner = new Scanner(System.in); // Create a Scanner object
System.out.print("Enter drug name: ");
String drugName = myScanner.nextLine(); // Read user input
System.out.print("Enter days of week: ");
String days = myScanner.nextLine(); // Read user input
System.out.print("Enter time of day: ");
String time = myScanner.nextLine(); // Read user input
System.out.print("Reminder ahead of time: ");
String reminderTime = myScanner.nextLine(); // Read user input
System.out.print("Repeat times: ");
String repeatTime = myScanner.nextLine(); // Read user input
System.out.print("Repeat intervals: ");
String repeatIntervals = myScanner.nextLine(); // Read user input
// putting data to JSONObject
jo.put("Drug", drugName);
jo.put("Days", days);
jo.put("Time to take", time);
jo.put("Reminder ahead to take", reminderTime);
// writing JSON to file:"JSONExample.json" in cwd
PrintWriter pw = new PrintWriter("WhenToDrug.json");
pw.write(jo.toJSONString());
pw.flush();
pw.close();
}
}