Note that there are some explanatory texts on larger screens.

plurals
  1. PO(non-static method Change(String,String,String) cannot be referenced from a static context
    text
    copied!<p>I've searched, but didn't understand how to incorporate previous answers with my own code. I have an assigment to create a draft of a program for the schools "bank/scholarship"-system. Here we need to create a lot of different methods, that should be called instead of just doing the change directly.</p> <p>The thing is, I keep getting the error-message in the topic along with a few others, and I don't know how to fix it. I would really appreciate if someone could explain for me how and why to change one of my methods, then I assume I will be able to rewrite all the others myself. Here is my code so far:</p> <p>class Address</p> <pre><code>public class Address { public String street, zip, post; public Address (String street, String zip, String post) { this.street = street; this.zip = zip; this.post = post; } // these are setters (mutators) public void setStreet (String street) { this.street = street; } public void setZip (String zip) { this.zip = zip; } public void setPost (String post) { this.post = post; } // these are getters public String getStreet () { return this.street; } public String getZip () { return zip; } public String getPost () { return post; } // methods //public Address Change(Address newAddress) { //return newAddress; //} // output public String toString() { return (street + ", " + zip + ", "+ post); } } </code></pre> <p>class Customer</p> <pre><code>import java.text.DecimalFormat; public class Customer { DecimalFormat twoD = new DecimalFormat("0.00"); Address address = new Address("Vik ", "6393 ", "Tomrefjord"); public String name, campus, newCampus, newAddress; public double loan, increase,decrease,regMaster; public boolean finished; public Customer (String name,Address address, String campus, double loan, boolean finished) { this.name = name; this.campus = campus; this.loan = loan; this.address = address; this.finished = finished; } // these are setters public void setName (String name) { this.name = name; } public void setCampus (String campus) { this.campus = campus; } public void setLoan (double loan) { this.loan = loan; } public void setFinished (boolean finished) { this.finished = finished; } // these are getters public String getName () { return name; } public String getCampus () { return campus; } public double getLoan () { return loan; } // methods public void RegMaster () { this.loan = loan * 0.90;} //public void changeAddress (Address newAddress) { //Address.Change(newAddress); } public double decreaseLoan (double currentBalance, double decrease) { currentBalance = currentBalance - decrease; return currentBalance; } public double getNewLoan (double currentBalance, double newLoan) { newLoan = currentBalance + newLoan; return newLoan; } public String getNewCampus (String newCampus) { campus = newCampus; return campus; } public static boolean Ended () { return true; } // output public String toString() { return (name + "\t\n" + address + "\t\n" + campus + "\t\n" + twoD.format(loan) + "\t\n" + finished); } } </code></pre> <p>class TestCustomer</p> <pre><code>import java.util.Scanner; public class TestCustomer { public static void main (String[] args) { String student, school, answer, street, zip, post; double balance, master; boolean finished = false; double done = 0; //this is for the loop Scanner scan = new Scanner(System.in); // a new student receives a loan System.out.println("Write your name"); student = scan.nextLine(); System.out.println("Enter your street name and number"); street = scan.nextLine(); System.out.println("What is your zip code?"); zip = scan.nextLine(); System.out.println("What is your post area?"); post = scan.nextLine(); System.out.println("Where do you study?"); school = scan.nextLine(); System.out.println("Input your current loan"); balance = scan.nextDouble(); Address residence = new Address(street, zip, post); Customer customer = new Customer(student, residence, school, balance, finished); while(done &lt; 1) { //the variable done will have the value 0 until you are finished. // change address System.out.println("Do you wish to change your address? (yes/no)"); answer = scan.nextLine(); if (answer.equalsIgnoreCase("yes")) { //this made it case-insensitive, and now it is not skipping anymore... System.out.println("Write your street name and house number"); street = scan.nextLine(); System.out.println("Write your zip code"); zip = scan.nextLine(); System.out.println("Write your post area"); post = scan.nextLine(); //Address newAddress = new Address(street, zip, post); //residence = Customer.changeAddress(newAddress); } // increase the loan System.out.println("Do you want to increase your loan? (yes/no)"); answer = scan.nextLine(); if (answer.equalsIgnoreCase("yes")) { System.out.println("How much do you need?"); double increaseLoan = scan.nextDouble(); //customer.balance = getNewLoan(customer.balance, moreLoan); } // decrease the loan System.out.println("Do you want to make a downpayment on your loan?"); answer = scan.nextLine(); if (answer.equalsIgnoreCase("yes")) { System.out.println("How much do you intend to pay?"); double downpayment = scan.nextDouble(); //customer.balance = decreaseLoan(customer.balance, downpayment); } // change school System.out.println("Do you study at the same school? (yes/no"); answer = scan.nextLine(); if (answer.equalsIgnoreCase("no")) { System.out.println("Write the name of the new school"); school = scan.nextLine(); } //school.getNewCampus(customer.campus); // master check System.out.println("Have you finished your master? (yes/no)"); answer = scan.nextLine(); if (answer.equalsIgnoreCase("yes")) { customer.finished = Customer.Ended() ; //this will set finished to true, using the method like intended //customer.balance = Customer.RegMaster(); // dont know how to invoke it... me neither -_- } System.out.println("Are you done? yes/no"); answer = scan.nextLine(); if (answer.equalsIgnoreCase("yes")) { done = 1; } // this adds 1 to the variable done, thus ending the loop. } // output System.out.println(""); System.out.println("The data we have so far is:"); System.out.println(customer); }} </code></pre> <p>Here are all three of my classes. Some of the functions are commented away, others are just not working properly (the code is also a little extra messy, I was changing back and forth to try to get it working yesterday). Any help will be appreciated! :)</p>
 

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