Work on credit union
This commit is contained in:
parent
4200233638
commit
b1ea675cb9
11
IN-CLASS-FEB-3-2021/Review.java
Normal file
11
IN-CLASS-FEB-3-2021/Review.java
Normal 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; }
|
||||
}
|
26
IN-CLASS-FEB-3-2021/ReviewSystem.java
Normal file
26
IN-CLASS-FEB-3-2021/ReviewSystem.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
44
IN-CLASS-FEB-3-2021/Reviews.java
Normal file
44
IN-CLASS-FEB-3-2021/Reviews.java
Normal 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());
|
||||
}
|
||||
}
|
44
arraylists-only-negative-numbers/arrayListFun.java
Normal file
44
arraylists-only-negative-numbers/arrayListFun.java
Normal 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();
|
||||
}
|
||||
}
|
19
mortgage-pre-approved-list/CreditUnion.java
Normal file
19
mortgage-pre-approved-list/CreditUnion.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
24
mortgage-pre-approved-list/HomeBuyer.java
Normal file
24
mortgage-pre-approved-list/HomeBuyer.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
0
mortgage-pre-approved-list/LabProgram.java
Normal file
0
mortgage-pre-approved-list/LabProgram.java
Normal file
31
mortgage-pre-approved-list/MyHomeBuyerTest.java
Normal file
31
mortgage-pre-approved-list/MyHomeBuyerTest.java
Normal 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());
|
||||
}
|
||||
}
|
87
mortgage-pre-approved-list/MyPreApprovedListTest.java
Normal file
87
mortgage-pre-approved-list/MyPreApprovedListTest.java
Normal 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());
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user