From 88ee1b4a3f6f492b42f17656a413603a563a223e Mon Sep 17 00:00:00 2001 From: DjBushido Date: Tue, 28 Jan 2014 17:09:38 -0500 Subject: [PATCH] Refactor PartOne.java --- .../uncc/itcs4180/PartOne}/PartOne.java | 90 +------------------ HW1/src/com/uncc/itcs4180/PartOne/User.java | 63 +++++++++++++ .../uncc/itcs4180/PartOne/UserComparator.java | 25 ++++++ 3 files changed, 91 insertions(+), 87 deletions(-) rename HW1/src/{edu/uncc/itcs4180 => com/uncc/itcs4180/PartOne}/PartOne.java (66%) create mode 100644 HW1/src/com/uncc/itcs4180/PartOne/User.java create mode 100644 HW1/src/com/uncc/itcs4180/PartOne/UserComparator.java diff --git a/HW1/src/edu/uncc/itcs4180/PartOne.java b/HW1/src/com/uncc/itcs4180/PartOne/PartOne.java similarity index 66% rename from HW1/src/edu/uncc/itcs4180/PartOne.java rename to HW1/src/com/uncc/itcs4180/PartOne/PartOne.java index 53973db..e2e835c 100644 --- a/HW1/src/edu/uncc/itcs4180/PartOne.java +++ b/HW1/src/com/uncc/itcs4180/PartOne/PartOne.java @@ -4,7 +4,7 @@ * Homework 1 * PartOne.java */ -package edu.uncc.itcs4180; +package com.uncc.itcs4180.PartOne; import java.io.BufferedReader; import java.io.FileReader; @@ -31,7 +31,7 @@ public class PartOne //We need a try catch block so we can handle any potential IO errors try { - //Try block so we can use efinallyf and close BufferedReader + //Try block so we can use finally? and close BufferedReader try { inputStream = new BufferedReader(new FileReader(filePath)); @@ -72,7 +72,7 @@ public class PartOne //We need a try catch block so we can handle any potential IO errors try { - //Try block so we can use efinallyf and close BufferedReader + //Try block so we can use finally and close BufferedReader try { inputStream = new BufferedReader(new FileReader(filePath)); @@ -112,88 +112,4 @@ public class PartOne System.out.println(user.getAge()); } } -} - -class User -{ - private String fname; - private char minit; - private String lname; - private int age; - - public User() - { - fname = "Default"; - minit = 'D'; - lname = "User"; - age = 0; - } - - public User(String fname, char minit, String lname, int age) - { - this.fname = fname; - this.minit = minit; - this.lname = lname; - this.age = age; - } - - public String getFname() - { - return this.fname; - } - - public char getMinit() - { - return this.minit; - } - - public String getLname() - { - return this.lname; - } - - public int getAge() - { - return this.age; - } - - public boolean equals(User user) - { - if(this.fname.equals(user.getFname()) && this.minit==user.getMinit() && this.lname.equals(user.getLname()) && this.age==user.getAge()) - { - return true; - } - else - { - return false; - } - } - - public String toString() - { - String userString = fname+" "+minit+" "+lname+" "+age; - return userString; - } -} - -class UserComparator implements Comparator -{ - public int compare(User a, User b) - { - if(a.getFname().equals(b.getFname()) && a.getMinit()==b.getMinit() && a.getLname().equals(b.getLname()) && a.getAge()==b.getAge()) - { - return 0; - } - else - { - if(a.getAge()>b.getAge()) - { - return 1; - } - else - { - return -1; - } - } - } } \ No newline at end of file diff --git a/HW1/src/com/uncc/itcs4180/PartOne/User.java b/HW1/src/com/uncc/itcs4180/PartOne/User.java new file mode 100644 index 0000000..d6fe772 --- /dev/null +++ b/HW1/src/com/uncc/itcs4180/PartOne/User.java @@ -0,0 +1,63 @@ +package com.uncc.itcs4180.PartOne; + +class User +{ + private String fname; + private char minit; + private String lname; + private int age; + + public User() + { + fname = "Default"; + minit = 'D'; + lname = "User"; + age = 0; + } + + public User(String fname, char minit, String lname, int age) + { + this.fname = fname; + this.minit = minit; + this.lname = lname; + this.age = age; + } + + public String getFname() + { + return this.fname; + } + + public char getMinit() + { + return this.minit; + } + + public String getLname() + { + return this.lname; + } + + public int getAge() + { + return this.age; + } + + public boolean equals(User user) + { + if(this.fname.equals(user.getFname()) && this.minit==user.getMinit() && this.lname.equals(user.getLname()) && this.age==user.getAge()) + { + return true; + } + else + { + return false; + } + } + + public String toString() + { + String userString = fname+" "+minit+" "+lname+" "+age; + return userString; + } +} \ No newline at end of file diff --git a/HW1/src/com/uncc/itcs4180/PartOne/UserComparator.java b/HW1/src/com/uncc/itcs4180/PartOne/UserComparator.java new file mode 100644 index 0000000..f32c95d --- /dev/null +++ b/HW1/src/com/uncc/itcs4180/PartOne/UserComparator.java @@ -0,0 +1,25 @@ +package com.uncc.itcs4180.PartOne; + +import java.util.Comparator; + +class UserComparator implements Comparator +{ + public int compare(User a, User b) + { + if(a.getFname().equals(b.getFname()) && a.getMinit()==b.getMinit() && a.getLname().equals(b.getLname()) && a.getAge()==b.getAge()) + { + return 0; + } + else + { + if(a.getAge()>b.getAge()) + { + return 1; + } + else + { + return -1; + } + } + } +} \ No newline at end of file