-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJataBase.java
More file actions
99 lines (89 loc) · 2.43 KB
/
Copy pathJataBase.java
File metadata and controls
99 lines (89 loc) · 2.43 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
/**
* Main class for the JataBase Database Management System.
* This is where the application first enters and begins
* databasing operations.
*
* by: Brandon Main
*
* last edit: February 20, 2019
*/
import java.lang.*;
import java.io.*;
import java.util.*;
public class JataBase
{
/**
* JataBase()
*
* Constructs the database management program object.
*
* @param args - A string of arguments.
*/
private JataBase(String[] args)
{
System.out.println("\nJataBase version 1.0 2019-02-05");
System.out.println("Written by: Brandon Main");
System.out.println("Enter \".EXIT\" to exit the program.");
//If args is empty, read from command line
//else, read from file.
if(args.length == 0)
{
String input = "";
//Read from command line
while(!input.equals(".EXIT"))
{
System.out.print("\nJataBase~# ");
input = System.console().readLine();
Instructions.operate(input);
}
}
else if(args.length == 1)
{
//Read from file
readFile(args[0]);
}
else
{
System.out.println("\nJataBase~# Improper usage. " +
"Usage is of the form:\n\n\t\tjava JataBase <NULL | <FILE>>\n");
}
}
/**
* readFile()
*
* Reads input file of instructions.
*
* @param arg - A String representing an input file.
*/
private void readFile(String arg)
{
File file = new File(arg);
System.out.println("\nReading from file " + file.toString() + " ...\n");
try
{
Scanner scanFile = new Scanner(file);
//Scan through whole file and operate on instructions.
while(scanFile.hasNext())
{
//Scan through String from file and operate on
//intructions.
Instructions.operate(scanFile.nextLine());
}
}
catch(FileNotFoundException e)
{
System.out.println("\nJataBase~# \tFile not Found! Please restart and try again.\n");
}
}
/**
* main()
*
* The main entrance to the JataBase program.
*
* @param args - Command line arguments.
*/
public static void main(String[] args)
{
new JataBase(args);
}
}