Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access my array in my method?
    primarykey
    data
    text
    <p>Here is my issue. I am trying to build an array of HomeLoan in my main, and then from my main, call the printHLoans(hLoans) from my main, so that I can list them and then add more functionality. Unfortunately, it is saying that hLoan cannot be resolved as a variable.</p> <p>Main Class</p> <pre><code>import java.util.InputMismatchException; import java.util.Scanner; public class LoanTest { static int term; static int loanID=0; static int hHowMany=0; static int cHowMany=0; public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.print("Enter name: "); String name = input.nextLine(); System.out.print("Enter Customer ID: "); int custID=0; do { try { custID = input.nextInt(); } catch (InputMismatchException e) { System.out.println("Customer IDs are numbers only"); input.next(); } }while (custID&lt;1); boolean aa=true; while(aa) { System.out.println("Do you have a (h)ome loan or a (c)ar loan?"); String a = input.next(); switch (a) { case "h": System.out.println("You selected Home Loan"); System.out.println("How many Home Loans would you like to enter?"); hHowMany = input.nextInt(); HomeLoan[] hLoans = new HomeLoan[hHowMany]; int z=0; while (hHowMany&gt;z) { hLoans[z] = new HomeLoan(name, custID); z++; } break; case "c": System.out.println("You selected Car Loan"); System.out.println("How many Car Loans would you like to enter?"); cHowMany = input.nextInt(); int x=0; CarLoan[] carLoans = new CarLoan[cHowMany]; while (x&lt;cHowMany) { System.out.print("Enter Loan ID: "); loanID=0; do { try { loanID=input.nextInt(); } catch (InputMismatchException e) { System.out.println("Loan IDs are number only"); input.next(); } }while (loanID&lt;1); boolean b=true; while(b) { System.out.print("Enter term: "); term=input.nextInt(); boolean t = CarLoan.termCorrect(term); if(t){System.out.println("Error: Maximum of 6 year");} else {b=false; System.out.println("You entered: " + term + " years");} } carLoans[x] = new CarLoan(name, custID, loanID, term); x++; } break; default: System.out.println("Invalid input"); break; } System.out.print("Would you like to enter another loan?"); System.out.print("(y)es or (n)o:"); String m = input.next(); System.out.println(""); switch (m) { case "y": break; case "n": aa=false; break; default: System.out.print("Invalid entry"); } } printHLoans(hLoans); System.out.println("Thank you for using Loan Software"); System.out.println("Have a nice day"); } public static void printHLoans(HomeLoan hLoans[]) { System.out.println("Here are the loans you entered . . ."); int zzz=0; while (zzz&lt;hHowMany) { term = hLoans[zzz].getTerm(); loanID=hLoans[zzz].getLoanID(); String address=hLoans[zzz].getAddress(); double loanAmount = hLoans[zzz].getLoanAmount(); System.out.print(zzz + ": "); System.out.print(hLoans[zzz].toString(loanID, address, term, loanAmount)); System.out.println(); zzz++; } } } </code></pre> <p>HomeLoan Class</p> <pre><code> import java.util.InputMismatchException; import java.util.Scanner; public class HomeLoan extends Loan { private String address; int howMany; private double loanAmount; private int term; private int loanID; public HomeLoan() { } public HomeLoan(String name, int custID) { //super(name, custID, loanID); Scanner input = new Scanner (System.in); System.out.print("Enter Loan ID: "); loanID=0; do { try { loanID=input.nextInt(); } catch (InputMismatchException e) { System.out.println("Loan IDs are number only"); input.next(); } }while (loanID&lt;1); boolean l=true; while (l) { System.out.print("Enter term: "); term=input.nextInt(); boolean s = HomeLoan.termCorrect(term); if (s){System.out.println("Error: Maximum of 30 years");} else {l=false;} } //System.out.println(); input.nextLine(); System.out.print("Enter your address: "); address=input.nextLine(); System.out.print("Enter loan ammount: "); loanAmount = input.nextDouble(); double annualInterest = 10.99; double monthlyPayment = amortization(loanAmount, annualInterest, term); double newBalance=payment(monthlyPayment, loanAmount); //System.out.println("Payment: " + monthlyPayment); //System.out.println("New balance after payment: " + newBalance); } public static boolean termCorrect(int term) { boolean a; if (term&gt;30) {a=true; return a;} else {a=false; return a;} } public String toString(String name, int custID, int loanID) { String display = "Name: " + name + " Customer ID: " + custID + " Address: "+ address+ " Loan ID: " + loanID + " Loan Amount: $" + loanAmount + " Current Balance: $"; return display; } public String getAddress() { return address; } public double getLoanAmount() { return loanAmount; } public int getTerm() { return term; } public int getLoanID() { return loanID; } public String toString(int loanID, String address, int term, double loanAmmount) { String displa = "ID: " + loanID + " Address:" + address + " Term: " + term + " Loan Ammount: " + loanAmmount; return displa; } private void equals() { } public void printHLoans(HomeLoan hLoans[], int xxx) { } } </code></pre> <p>How do I make this work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload