Java if / else语句

问题描述 投票:-1回答:2

我正在计算机类中完成我的最终项目,并试图在嵌套类中实现基本的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语句更改为不仅打印不合格,那么>]

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

java class if-statement superclass
2个回答
0
投票

此问题不包含问题,但我看到了问题区域。


0
投票
  1. user_State实例变量没有设置方法
© www.soinside.com 2019 - 2024. All rights reserved.