Java if / else语句

我正在计算机类中的最后一个项目上工作,并试图在嵌套类中实现基本的if / else语句,但是它仅选择使用else情况。 导入java.util.Scanner;

public class CollegeApplication {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       //create object by default constructor
       College c1 = new College();
       //create object by overloaded constructor
       College c2 = new College("Frostburg", "Frostburg", "MD", 5142);
       College c3 = new College("UMBC", "Baltimore", "MD", 14000);
       //set the information of object 1
       c1.setName("Full Sail");
       c1.setCity("Winter Park");
       c1.setState("FL");
       c1.setStudent_Body(19285);

       System.out.println("Enter your states two-letter abbreviation");
       String user_State = scan.nextLine();

       c1.printCollege();
       System.out.println();
       c2.printCollege();
       System.out.println();
       c3.printCollege();
   }
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
import java.util.Scanner;

public class College {

   // private data members
   private String name;
   private String city;
   private String state;
   private int student_Body;
   private String tuition;
   private String user_State;

   // default constructor which set the data member to default value
   public College() {

       this.name = "";
       this.city = "";
       this.state = "";
       this.student_Body = 0;
       this.tuition = "";
       this.user_State = "";
   }

   // parameterized constructor
   public College(String name, String city, String state, int student_Body) {
       super();
       this.name = name;
       this.city = city;
       this.state = state;
       this.student_Body = student_Body;
   }

   // getter and setter
   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getCity() {
       return city;
   }

   public void setCity(String city) {
       this.city = city;
   }

   public String getState() {
      return state;
   }

   public void setState(String state) {
      this.state = state;  
   }

   public int getStudent_Body() {
       return student_Body;
   }

   public void setStudent_Body(int student_Body) {
       this.student_Body = student_Body;
   }    
   // print college data
   public void printCollege() {

       System.out.println("Name of College: " + name);
       System.out.println("City of Collge: " + city);
       System.out.println("State of Collge: " + state);
       System.out.println("Student Body Count: " + student_Body);

   this.user_State = user_State;
      if (state.equals(user_State)) {
         this.tuition = "Eligible";
      }
      else {
         this.tuition = "Ineligible";
      }

       System.out.println("In-State Tuition: " + tuition); 
   }
}

如果有人可以帮助id在知道如何将if语句更改为不仅不合格的情况下非常感激

评论