mirror of
https://github.com/bspeice/itcs4180
synced 2024-11-08 08:28:14 -05:00
Refactor PartOne.java
This commit is contained in:
parent
fcbd74a5e4
commit
88ee1b4a3f
@ -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 <EFBFBD>efinally<EFBFBD>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 <EFBFBD>efinally<EFBFBD>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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
HW1/src/com/uncc/itcs4180/PartOne/User.java
Normal file
63
HW1/src/com/uncc/itcs4180/PartOne/User.java
Normal 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;
|
||||
}
|
||||
}
|
25
HW1/src/com/uncc/itcs4180/PartOne/UserComparator.java
Normal file
25
HW1/src/com/uncc/itcs4180/PartOne/UserComparator.java
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user