Work on credit union

This commit is contained in:
Logen Kain 2021-02-03 14:34:48 -05:00
parent 4200233638
commit b1ea675cb9
9 changed files with 286 additions and 0 deletions

View File

@ -0,0 +1,11 @@
public class Review {
private int rating = -1;
private String comment = "NoComment";
public void setRatingAndComment(int revRating, String revComment) {
this.rating = revRating;
comment = revComment;
}
public int getRating() { return rating; }
public String getComment() { return comment; }
}

View File

@ -0,0 +1,26 @@
import java.util.ArrayList;
import java.util.Scanner;
public class ReviewSystem {
public static void main(String [] args) {
Scanner scnr = new Scanner(System.in);
Reviews allReviews = new Reviews();
String currName;
int currRating;
System.out.println("Type rating + comments. To end: -1");
allReviews.inputReviews(scnr);
System.out.println("\nAverage rating: ");
System.out.println(allReviews.getAverageRating());
// Output all comments for given rating
System.out.println("\nType rating. To end: -1");
currRating = scnr.nextInt();
while (currRating != -1) {
allReviews.printCommentsForRating(currRating);
currRating = scnr.nextInt();
}
}
}

View File

@ -0,0 +1,44 @@
import java.util.ArrayList;
import java.util.Scanner;
public class Reviews {
private ArrayList<Review> reviewList = new ArrayList<Review>();
public void inputReviews(Scanner scnr) {
Review currReview;
int currRating;
String currComment;
currRating = scnr.nextInt();
while (currRating >= 0) {
currReview = new Review();
currComment = scnr.nextLine(); // Gets rest of line
currReview.setRatingAndComment(currRating, currComment);
reviewList.add(currReview);
currRating = scnr.nextInt();
}
}
public void printCommentsForRating(int currRating) {
Review currReview;
int i;
for (i = 0; i < reviewList.size(); ++i) {
currReview = reviewList.get(i);
if (currRating == currReview.getRating()) {
System.out.println(currReview.getComment());
}
}
}
public int getAverageRating() {
int ratingsSum;
int i;
ratingsSum = 0;
for (i = 0; i < reviewList.size(); ++i) {
ratingsSum += reviewList.get(i).getRating();
}
return (ratingsSum / reviewList.size());
}
}

View File

@ -0,0 +1,44 @@
/*
* 6 ints will be put into an ArrayList listInts
* copy only negative ints to a new ArrayList listNegInts
* Output the number of negative elements and the negatives list
*
* input: 5 -2 0 9 -66 -4
* output:
* 3
* -2
* -66
* -4
*/
import java.util.Scanner;
import java.util.ArrayList;
public class arrayListFun{
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
ArrayList<Integer> listInts = new ArrayList<>();
ArrayList<Integer> listNegInts = new ArrayList<>();
//take in array list listInts TODO
for (int i =0; i<6;i++){
listInts.add(scnr.nextInt());
}
//Find negative INTS and make a list
for (int i:listInts){
if (i<0){
listNegInts.add(i);
}
}
//Print out the neg list size and print out the contents
System.out.println(listNegInts.size());
for (int i:listNegInts){
System.out.println(i);
}
scnr.close();
}
}

View File

@ -0,0 +1,19 @@
import java.util.ArrayList;
public class CreditUnion{
//ArrayList of HomeBuyer objects as borrower roster
ArrayList<HomeBuyer> homeBuyers = new ArrayList<HomeBuyer>();
public ArrayList<HomeBuyer> getPreApprovedList(){
ArrayList<HomeBuyer> approvedHomeBuyerList = new ArrayList<HomeBuyer>();
for (HomeBuyer buyer:homeBuyers){
if (buyer.getCreditScore()>=700){
approvedHomeBuyerList.add(buyer);
}
}
return approvedHomeBuyerList;
}
}

View File

@ -0,0 +1,24 @@
public class HomeBuyer{
//.getFirst .getLast .getCreditScore
//constructed as (first, last, score)
private String fName, lName;
private int creditScore;
public HomeBuyer(String fName, String lName, int creditScore){
this.fName = fName;
this.lName = lName;
this.creditScore = creditScore;
}
public String getFirst(){
return fName;
}
public String getLast(){
return lName;
}
public int getCreditScore(){
return creditScore;
}
}

View File

@ -0,0 +1,31 @@
import org.junit.*;
/****************************************************
* MyCarTestPhase1 - to test the class Car Phase1
*
* @author Resendiz
* @version February 2021
****************************************************/
public class MyHomeBuyerTest {
/******************************************************
* Test default constructor - no input parameters
*****************************************************/
@Test
public void testConstructor() {
HomeBuyer buyer = new HomeBuyer("Jon", "Smith", 650);
Assert.assertEquals("Buyer's first name should be:", "Jon", buyer.getFirst());
Assert.assertEquals("Buyer's last name should be", "Smith", buyer.getLast());
Assert.assertEquals("Buyer's Credit Score should be: ", 650, buyer.getCreditScore());
}
/******************************************************
* Test toString Method
*****************************************************/
@Test
public void testToStringMethod() {
HomeBuyer buyer = new HomeBuyer("Jon", "Smith", 650);
Assert.assertEquals("The toString method should be: ",
"Jon Smith (Credit Score: 650)", buyer.toString());
}
}

View File

@ -0,0 +1,87 @@
import org.junit.*;
import java.util.ArrayList;
import static org.junit.Assert.*;
/****************************************************
* MyCarTestPhase1 - to test the class Car Phase1
*
* @author Resendiz
* @version February 2021
****************************************************/
public class MyPreApprovedListTest {
/******************************************************
* Test default constructor - no input parameters
*****************************************************/
@Test
public void testConstructor() {
/* Credit Union */
CreditUnion cu = new CreditUnion();
assertEquals("ArrayList should contain no records at this time",
0, cu.getPreApprovedList().size());
}
/******************************************************
* Test Pre-Approved List with Zero Credit Scores above or equal at 700
*****************************************************/
@Test
public void testNoGoodCreditScores() {
/* Credit Union */
CreditUnion cu = new CreditUnion();
cu.addHomeBuyer(new HomeBuyer("first","last",600));
cu.addHomeBuyer(new HomeBuyer("first","last",650));
cu.addHomeBuyer(new HomeBuyer("first","last",500));
cu.addHomeBuyer(new HomeBuyer("first","last",599));
cu.addHomeBuyer(new HomeBuyer("first","last",699));
ArrayList<HomeBuyer> preApprovedList = cu.getPreApprovedList();
assertEquals("preApprovedList.size() should have returned 0 buyers " +
"on the pre-approved list but incorrectly returned " + preApprovedList.size(),
0, preApprovedList.size());
}
/******************************************************
* Test Pre-Approved List with One Credit Score above or equal at 700
*****************************************************/
@Test
public void testOneGoodCreditScores() {
/* Credit Union */
CreditUnion cu = new CreditUnion();
cu.addHomeBuyer(new HomeBuyer("first","last",600));
cu.addHomeBuyer(new HomeBuyer("first","last",650));
cu.addHomeBuyer(new HomeBuyer("first","last",800));
cu.addHomeBuyer(new HomeBuyer("first","last",599));
cu.addHomeBuyer(new HomeBuyer("first","last",699));
ArrayList<HomeBuyer> preApprovedList = cu.getPreApprovedList();
assertEquals("preApprovedList.size() should have returned 1 buyer " +
"on the pre-approved list but incorrectly returned " + preApprovedList.size(),
1, preApprovedList.size());
}
/******************************************************
* Test Pre-Approved List with Two Credit Score above or equal at 700
*****************************************************/
@Test
public void testTwoGoodCreditScores() {
/* Credit Union */
CreditUnion cu = new CreditUnion();
cu.addHomeBuyer(new HomeBuyer("first","last",700));
cu.addHomeBuyer(new HomeBuyer("first","last",650));
cu.addHomeBuyer(new HomeBuyer("first","last",800));
cu.addHomeBuyer(new HomeBuyer("first","last",599));
cu.addHomeBuyer(new HomeBuyer("first","last",699));
ArrayList<HomeBuyer> preApprovedList = cu.getPreApprovedList();
assertEquals("preApprovedList.size() should have returned 2 buyers " +
"on the pre-approved list but incorrectly returned " + preApprovedList.size(),
2, preApprovedList.size());
}
}