moved main functions
This commit is contained in:
parent
59c0b1d3f9
commit
7b6b15d1d2
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
/target/
|
||||
|
@ -12,66 +12,7 @@ public class Main {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Person p = new Person(12345, "Hesham", Level.BA);
|
||||
System.out.println("-------------------------------------------------");
|
||||
Scanner in = new Scanner(System.in);
|
||||
System.out.print("Name: ");
|
||||
p.getAccount().setName(in.nextLine());
|
||||
System.out.print("ID: ");
|
||||
p.getAccount().setID(in.nextInt());
|
||||
System.out.print("Account Type (Cheking, Investing, Saving): ");
|
||||
p.getAccount().setAccountType(parseType(in.next()));
|
||||
System.out.print("School: ");
|
||||
p.getEdu().setSchool(in.next());
|
||||
System.out.print("Major: ");
|
||||
p.getEdu().setMajor(in.next());
|
||||
List<Course> list = Arrays.asList(Course.EE201, Course.EE250,Course.ISLS201);
|
||||
p.getEdu().addCourses(list);
|
||||
Print(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the correct enum value of the parameter.
|
||||
* @param a string naming the account type
|
||||
* @return AccountType
|
||||
* @since 0.1
|
||||
* @exception IncorrectStringException
|
||||
*/
|
||||
private static AccountType parseType(String input) {
|
||||
switch(input) {
|
||||
case "Investing":
|
||||
return AccountType.Investing;
|
||||
case "Saving":
|
||||
return AccountType.Saving;
|
||||
default:
|
||||
return AccountType.Checking;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Standered print of Person's information
|
||||
* @param Person Object.
|
||||
* @since 0.1
|
||||
*/
|
||||
public static void Print(Person p) {
|
||||
LocalDate date = new LocalDate();
|
||||
|
||||
System.out.println(
|
||||
"\n\n\n\t---------INFO---------\n"
|
||||
+ "\t --- "+ date.toString()+" ---\n"
|
||||
+ "\tName: "+p.getAccount().getName()+"\n"
|
||||
+ "\tID: "+p.getAccount().getID()+"\n"
|
||||
+ "\tMajor: "+p.getEdu().getMajor()+"\n"
|
||||
+ "\tSchool: "+p.getEdu().getSchool()+"\n"
|
||||
+ "\tCity: "+p.getLocation().cityBasedOnIP()+"\n"
|
||||
+ "\tAccountType: "+p.getAccount().getAccountType()+"\n"
|
||||
+ "\t---------COURSES---------");
|
||||
int i = 1;
|
||||
for (Course course : p.getEdu().getCourses()) {
|
||||
System.out.println("\tCourse "+i+": "+course.name());
|
||||
}
|
||||
|
||||
Questions.run();
|
||||
|
||||
}
|
||||
}
|
||||
|
85
src/Questions.java
Normal file
85
src/Questions.java
Normal file
@ -0,0 +1,85 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
public class Questions {
|
||||
|
||||
|
||||
public static void run(){
|
||||
Person p = new Person(12345, "Hesham", Level.BA);
|
||||
System.out.println("-------------------------------------------------");
|
||||
Scanner in = new Scanner(System.in);
|
||||
p.getAccount().setName(askForName(in));
|
||||
System.out.print("ID: ");
|
||||
p.getAccount().setID(in.nextInt());
|
||||
System.out.print("Account Type (Cheking, Investing, Saving): ");
|
||||
p.getAccount().setAccountType(parseType(in.next()));
|
||||
System.out.print("School: ");
|
||||
p.getEdu().setSchool(in.next());
|
||||
System.out.print("Major: ");
|
||||
p.getEdu().setMajor(in.next());
|
||||
in.close();
|
||||
List<Course> list = Arrays.asList(Course.EE201, Course.EE250,Course.ISLS201);
|
||||
p.getEdu().addCourses(list);
|
||||
Print(p);
|
||||
}
|
||||
|
||||
private static String askForName(Scanner in) {
|
||||
String name = null;
|
||||
System.out.print("Name: ");
|
||||
try {
|
||||
name = in.nextLine();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standered print of Person's information
|
||||
* @param Person Object.
|
||||
* @since 0.1
|
||||
*/
|
||||
private static void Print(Person p) {
|
||||
LocalDate date = new LocalDate();
|
||||
|
||||
System.out.println(
|
||||
"\n\n\n\t---------INFO---------\n"
|
||||
+ "\t --- "+ date.toString()+" ---\n"
|
||||
+ "\tName: "+p.getAccount().getName()+"\n"
|
||||
+ "\tID: "+p.getAccount().getID()+"\n"
|
||||
+ "\tMajor: "+p.getEdu().getMajor()+"\n"
|
||||
+ "\tSchool: "+p.getEdu().getSchool()+"\n"
|
||||
+ "\tCity: "+p.getLocation().cityBasedOnIP()+"\n"
|
||||
+ "\tAccountType: "+p.getAccount().getAccountType()+"\n"
|
||||
+ "\t---------COURSES---------");
|
||||
int i = 1;
|
||||
for (Course course : p.getEdu().getCourses()) {
|
||||
System.out.println("\tCourse "+i+": "+course.name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the correct enum value of the parameter.
|
||||
* @param a string naming the account type
|
||||
* @return AccountType
|
||||
* @since 0.1
|
||||
* @exception IncorrectStringException
|
||||
*/
|
||||
private static AccountType parseType(String input) {
|
||||
switch(input) {
|
||||
case "Investing":
|
||||
return AccountType.Investing;
|
||||
case "Saving":
|
||||
return AccountType.Saving;
|
||||
default:
|
||||
return AccountType.Checking;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user