From b1ea675cb980ee6c14b78a4e54a9540cda27396c Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 3 Feb 2021 14:34:48 -0500 Subject: [PATCH] Work on credit union --- IN-CLASS-FEB-3-2021/Review.java | 11 +++ IN-CLASS-FEB-3-2021/ReviewSystem.java | 26 ++++++ IN-CLASS-FEB-3-2021/Reviews.java | 44 ++++++++++ .../arrayListFun.java | 44 ++++++++++ mortgage-pre-approved-list/CreditUnion.java | 19 ++++ mortgage-pre-approved-list/HomeBuyer.java | 24 +++++ mortgage-pre-approved-list/LabProgram.java | 0 .../MyHomeBuyerTest.java | 31 +++++++ .../MyPreApprovedListTest.java | 87 +++++++++++++++++++ 9 files changed, 286 insertions(+) create mode 100644 IN-CLASS-FEB-3-2021/Review.java create mode 100644 IN-CLASS-FEB-3-2021/ReviewSystem.java create mode 100644 IN-CLASS-FEB-3-2021/Reviews.java create mode 100644 arraylists-only-negative-numbers/arrayListFun.java create mode 100644 mortgage-pre-approved-list/CreditUnion.java create mode 100644 mortgage-pre-approved-list/HomeBuyer.java create mode 100644 mortgage-pre-approved-list/LabProgram.java create mode 100644 mortgage-pre-approved-list/MyHomeBuyerTest.java create mode 100644 mortgage-pre-approved-list/MyPreApprovedListTest.java diff --git a/IN-CLASS-FEB-3-2021/Review.java b/IN-CLASS-FEB-3-2021/Review.java new file mode 100644 index 0000000..4330999 --- /dev/null +++ b/IN-CLASS-FEB-3-2021/Review.java @@ -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; } +} diff --git a/IN-CLASS-FEB-3-2021/ReviewSystem.java b/IN-CLASS-FEB-3-2021/ReviewSystem.java new file mode 100644 index 0000000..32b60d0 --- /dev/null +++ b/IN-CLASS-FEB-3-2021/ReviewSystem.java @@ -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(); + } + } +} \ No newline at end of file diff --git a/IN-CLASS-FEB-3-2021/Reviews.java b/IN-CLASS-FEB-3-2021/Reviews.java new file mode 100644 index 0000000..1409572 --- /dev/null +++ b/IN-CLASS-FEB-3-2021/Reviews.java @@ -0,0 +1,44 @@ +import java.util.ArrayList; +import java.util.Scanner; + +public class Reviews { + private ArrayList reviewList = new ArrayList(); + + 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()); + } +} \ No newline at end of file diff --git a/arraylists-only-negative-numbers/arrayListFun.java b/arraylists-only-negative-numbers/arrayListFun.java new file mode 100644 index 0000000..d8b227a --- /dev/null +++ b/arraylists-only-negative-numbers/arrayListFun.java @@ -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 listInts = new ArrayList<>(); + ArrayList 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(); + } +} diff --git a/mortgage-pre-approved-list/CreditUnion.java b/mortgage-pre-approved-list/CreditUnion.java new file mode 100644 index 0000000..c373478 --- /dev/null +++ b/mortgage-pre-approved-list/CreditUnion.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; + +public class CreditUnion{ + //ArrayList of HomeBuyer objects as borrower roster + ArrayList homeBuyers = new ArrayList(); + + public ArrayList getPreApprovedList(){ + + ArrayList approvedHomeBuyerList = new ArrayList(); + + for (HomeBuyer buyer:homeBuyers){ + if (buyer.getCreditScore()>=700){ + approvedHomeBuyerList.add(buyer); + } + } + return approvedHomeBuyerList; + } + +} diff --git a/mortgage-pre-approved-list/HomeBuyer.java b/mortgage-pre-approved-list/HomeBuyer.java new file mode 100644 index 0000000..0a506b3 --- /dev/null +++ b/mortgage-pre-approved-list/HomeBuyer.java @@ -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; + } + +} diff --git a/mortgage-pre-approved-list/LabProgram.java b/mortgage-pre-approved-list/LabProgram.java new file mode 100644 index 0000000..e69de29 diff --git a/mortgage-pre-approved-list/MyHomeBuyerTest.java b/mortgage-pre-approved-list/MyHomeBuyerTest.java new file mode 100644 index 0000000..659d34f --- /dev/null +++ b/mortgage-pre-approved-list/MyHomeBuyerTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/mortgage-pre-approved-list/MyPreApprovedListTest.java b/mortgage-pre-approved-list/MyPreApprovedListTest.java new file mode 100644 index 0000000..57fcd4c --- /dev/null +++ b/mortgage-pre-approved-list/MyPreApprovedListTest.java @@ -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 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 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 preApprovedList = cu.getPreApprovedList(); + + assertEquals("preApprovedList.size() should have returned 2 buyers " + + "on the pre-approved list but incorrectly returned " + preApprovedList.size(), + 2, preApprovedList.size()); + } + + +} \ No newline at end of file