mardi 26 novembre 2019

Java method taking 0 arguments and returning a double using if else statements with strings

I am trying to write a method which does not take any arguments and then returns a double variable. It is a postcode identifier so when a cost code is entered certain post codes need to return a double. In my example below i need post codes that start with either "GH6 TXX" or "NC4 LXX". (X stands for any random character or digit) to return 50.0. If any other postcode is entered then return 100.0.

However i am not getting any results back and just finding errors. I'm sure i have gone massive wrong somewhere as im not great with If Else statements within methods. Any help or knowledge on this would be great!

    public class multiPostcodeRange {
  //Declaring Variables
  String pcode;

  public multiPostcodeRange()
  {
     pcode = "XXX XXX";
  }

  public void multiPostcodeRange()
  {
     if (pcode("GH6 TXX", "NC4 LXX")) {
        return 100.0; }

        else {
           return 50.0;}
  }   }

Aucun commentaire:

Enregistrer un commentaire