Base
This commit is contained in:
parent
489c27fa36
commit
d46111b059
20
.classpath
Normal file
20
.classpath
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/classes" path="src">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Java</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
13
.settings/org.eclipse.jdt.core.prefs
Normal file
13
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,13 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
27
pom.xml
Normal file
27
pom.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>Java</groupId>
|
||||
<artifactId>Java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>JavaTesting</name>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
56
src/Account.java
Normal file
56
src/Account.java
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
public class Account {
|
||||
|
||||
private String Name;
|
||||
private int ID;
|
||||
private AccountType type;
|
||||
private double balance;
|
||||
|
||||
public Account(String name, int ID, AccountType type) {
|
||||
this.ID = ID;
|
||||
this.Name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Account(String name, int ID) {
|
||||
this.ID = ID;
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
public void credit(double c) {
|
||||
balance += c;
|
||||
}
|
||||
|
||||
public void debit(double d) {
|
||||
balance -= d;
|
||||
}
|
||||
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public void setID(int iD) {
|
||||
ID = iD;
|
||||
}
|
||||
|
||||
public void setAccountType(AccountType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public AccountType getAccountType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
}
|
6
src/AccountType.java
Normal file
6
src/AccountType.java
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
public enum AccountType {
|
||||
Checking,
|
||||
Saving,
|
||||
Investing
|
||||
}
|
57
src/Car.java
Normal file
57
src/Car.java
Normal file
@ -0,0 +1,57 @@
|
||||
|
||||
public class Car {
|
||||
|
||||
private String make;
|
||||
private int yearMade;
|
||||
private float engineSize;
|
||||
private int numberOfCylinders;
|
||||
private int capacity;
|
||||
private float currentSpeed;
|
||||
private Location location;
|
||||
|
||||
public String getMake() {
|
||||
return make;
|
||||
}
|
||||
public void setMake(String make) {
|
||||
this.make = make;
|
||||
}
|
||||
public int getYearMade() {
|
||||
return yearMade;
|
||||
}
|
||||
public void setYearMade(int yearMade) {
|
||||
this.yearMade = yearMade;
|
||||
}
|
||||
public float getEngineSize() {
|
||||
return engineSize;
|
||||
}
|
||||
public void setEngineSize(float engineSize) {
|
||||
this.engineSize = engineSize;
|
||||
}
|
||||
public int getNumberOfCylinders() {
|
||||
return numberOfCylinders;
|
||||
}
|
||||
public void setNumberOfCylinders(int numberOfCylinders) {
|
||||
this.numberOfCylinders = numberOfCylinders;
|
||||
}
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
public void setCapacity(int capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
public float getCurrentSpeed() {
|
||||
return currentSpeed;
|
||||
}
|
||||
public void setCurrentSpeed(float currentSpeed) {
|
||||
this.currentSpeed = currentSpeed;
|
||||
}
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
36
src/Education.java
Normal file
36
src/Education.java
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
public class Education {
|
||||
private String School;
|
||||
private String Major;
|
||||
private Level level;
|
||||
|
||||
public Education(String school, String major, Level lvl) {
|
||||
School = school;
|
||||
Major = major;
|
||||
level = lvl;
|
||||
}
|
||||
|
||||
public String getSchool() {
|
||||
return School;
|
||||
}
|
||||
|
||||
public void setSchool(String school) {
|
||||
School = school;
|
||||
}
|
||||
|
||||
public String getMajor() {
|
||||
return Major;
|
||||
}
|
||||
|
||||
public void setMajor(String major) {
|
||||
Major = major;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
}
|
||||
|
8
src/Level.java
Normal file
8
src/Level.java
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
public enum Level {
|
||||
High ,
|
||||
BA,
|
||||
Master,
|
||||
PHD
|
||||
|
||||
}
|
103
src/Location.java
Normal file
103
src/Location.java
Normal file
@ -0,0 +1,103 @@
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class Location {
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
private String city;
|
||||
|
||||
public Location(double lat, double lon) {
|
||||
latitude = lat;
|
||||
longitude = lon;
|
||||
city = cityBasedOnIP();
|
||||
}
|
||||
|
||||
public Location() {
|
||||
city = cityBasedOnIP();
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public void setLocation(double lat, double lon) {
|
||||
this.latitude = lat;
|
||||
this.longitude = lon;
|
||||
}
|
||||
|
||||
private String cityBasedOnIP() {
|
||||
String city = "";
|
||||
try {
|
||||
|
||||
URL url = new URL("http://ip-api.com/json");
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
int status = con.getResponseCode();
|
||||
BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer content = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
Object resultObject = parser.parse(content.toString());
|
||||
|
||||
if (resultObject instanceof JSONArray) {
|
||||
JSONArray array=(JSONArray)resultObject;
|
||||
for (Object object : array) {
|
||||
JSONObject obj =(JSONObject)object;
|
||||
city = (String)obj.get("city");
|
||||
}
|
||||
|
||||
}
|
||||
else if (resultObject instanceof JSONObject) {
|
||||
JSONObject obj =(JSONObject)resultObject;
|
||||
city = (String)obj.get("city");
|
||||
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (ProtocolException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return city;
|
||||
}
|
||||
}
|
59
src/Main.java
Normal file
59
src/Main.java
Normal file
@ -0,0 +1,59 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Person p = new Person(12345, "Hesham", Level.BA);
|
||||
System.out.println(p.getLocation().getCity());
|
||||
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());
|
||||
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) {
|
||||
System.out.println(
|
||||
"\t---------INFO---------\n"
|
||||
+ "\tName: "+p.getAccount().getName()+"\n"
|
||||
+ "\tID: "+p.getAccount().getID()+"\n"
|
||||
+ "\tMajor: "+p.getEdu().getMajor()+"\n"
|
||||
+ "\tSchool: "+p.getEdu().getSchool()+"\n"
|
||||
+ "\tAccountType: "+p.getAccount().getAccountType());
|
||||
|
||||
|
||||
}
|
||||
}
|
64
src/Person.java
Normal file
64
src/Person.java
Normal file
@ -0,0 +1,64 @@
|
||||
public class Person {
|
||||
|
||||
private Account account;
|
||||
private Education edu;
|
||||
private String name;
|
||||
private Car car;
|
||||
private Location location;
|
||||
|
||||
|
||||
public Person(int ID, String name, Level lvl) {
|
||||
account = new Account(name,ID);
|
||||
edu = new Education(null, null, lvl);
|
||||
car = new Car();
|
||||
location = new Location();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public Education getEdu() {
|
||||
return edu;
|
||||
}
|
||||
|
||||
public Car getCar() {
|
||||
return car;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void setCar(Car car) {
|
||||
this.car = car;
|
||||
}
|
||||
|
||||
public boolean hasCar() {
|
||||
if (car.getMake() != null) {
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public boolean isPHD() {
|
||||
if (this.edu.getLevel() == Level.PHD) {
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user