Hello everyone!
I was busy writing an application program with mulitple classes, and it deteremines if a applicant is approved or not is like an application database. I was running through the first two options, and noticed that a boolean was returning incorrectly. I know this is simple, but the coding looks fine to me. Here's the ApplyList class code that puts everything an applicant says into ArrayLists:
import java.util.ArrayList; public class ApplyList { Applicant app = new Applicant(); static ArrayList <String> FirstName = new ArrayList <String>(); static ArrayList <String> LastName = new ArrayList <String>(); static ArrayList <String> SSN = new ArrayList <String>(); static ArrayList <String> Approved = new ArrayList <String>(); static String temp; static String temp1; static String temp2; static String temp3; public void List() { FirstName.add(Applicant.Firstname); LastName.add(Applicant.Lastname); SSN.add(Applicant.SSN); if(Applicant.pending) Approved.add("Approved"); else Approved.add("Denied"); for(int q = 0; q <FirstName.size(); q++){ System.out.println((q + 1) +". " + FirstName.get(q) + " " + LastName.get(q) + " " + SSN.get(q) + " " + Approved.get(q)); }
Here's the Applicant Class, where the information is inputted:
import java.util.*; public class Applicant { public static String Firstname; public static String Lastname; public static String SSN; public static String Married; public static boolean pending; int income, age, approval; public static int run = 0; public void App(){ Scanner indata = new Scanner(System.in); System.out.println("Please enter your first name: "); Firstname = indata.next(); System.out.println("Please enter your last name: "); Lastname = indata.next(); System.out.println("Please enter your Social Security Number: "); SSN = indata.next(); System.out.println("Please enter your yearly income: "); income = indata.nextInt(); System.out.println("Please enter your marital status(Y/N): "); Married = indata.next(); System.out.println("Please enter your age: "); age = indata.nextInt(); if(Married.equals("y") || Married.equals("Y")){ income += 5000; } approval = (income / 1000)/ age; run++; } void Approve(){ App(); pending = Yes(); } public boolean Yes(){ return (approval >= 1.0); } }
And finally here's the main class that runs everything:
import java.util.*; public class ApplicationCenter { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner indata = new Scanner(System.in); ApplyList list = new ApplyList(); Applicant app = new Applicant(); int selection = 0; String choice; do{ System.out.println("1. Add an applicant"); System.out.println("2. Search applicants by Social Security Number"); System.out.println("3. View a list of all applicants"); System.out.println("4. View a list of approved applicants"); System.out.println("5. View a list of declined applicants"); System.out.println("6. Exit the Application Database"); selection = indata.nextInt(); switch(selection){ case 1 : System.out.println("You've decided to fill out an application."); System.out.println(); app.App(); list.List(); System.out.println(); break; case 2 : System.out.println("You've decided to search for an applicant by Social Security Number."); System.out.println(); System.out.println("Please enter the Social Security Number you would like to search: "); choice = indata.next(); int location = Collections.binarySearch(ApplyList.SSN, choice); if(location >= 0){ System.out.println("Applicant found: "); System.out.println((ApplyList.FirstName.get(location)) + " " + (ApplyList.LastName.get(location)) + ", " + ApplyList.SSN.get(location) + ", Status: "); if("Y".compareTo(ApplyList.Approved.get(location)) == 0){ System.out.println("Approved"); } } System.out.println(); break; case 3 : System.out.println("You've decided to view a list of all applicants."); for(int q = 0; q < ApplyList.FirstName.size(); q++){ System.out.println((q + 1) +". " + ApplyList.FirstName.get(q) + " " + ApplyList.LastName.get(q) + " " + ApplyList.SSN.get(q) + " " + ApplyList.Approved.get(q)); } break;
Thanks in advance for any help you can give.