1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-12-04 13:18:16 -05:00

Refactor PartOne.java

This commit is contained in:
DjBushido 2014-01-28 17:09:38 -05:00
parent fcbd74a5e4
commit 88ee1b4a3f
3 changed files with 91 additions and 87 deletions

View File

@ -4,7 +4,7 @@
* Homework 1 * Homework 1
* PartOne.java * PartOne.java
*/ */
package edu.uncc.itcs4180; package com.uncc.itcs4180.PartOne;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; 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 //We need a try catch block so we can handle any potential IO errors
try try
{ {
//Try block so we can use <EFBFBD>efinally<EFBFBD>f and close BufferedReader //Try block so we can use finally? and close BufferedReader
try try
{ {
inputStream = new BufferedReader(new FileReader(filePath)); 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 //We need a try catch block so we can handle any potential IO errors
try try
{ {
//Try block so we can use <EFBFBD>efinally<EFBFBD>f and close BufferedReader //Try block so we can use finally and close BufferedReader
try try
{ {
inputStream = new BufferedReader(new FileReader(filePath)); inputStream = new BufferedReader(new FileReader(filePath));
@ -112,88 +112,4 @@ public class PartOne
System.out.println(user.getAge()); 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<User>
{
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;
}
}
}
} }

View File

@ -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;
}
}

View File

@ -0,0 +1,25 @@
package com.uncc.itcs4180.PartOne;
import java.util.Comparator;
class UserComparator implements Comparator<User>
{
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;
}
}
}
}