首页 > 技术文章 > Java 学生类 姓名、学号、学院学校、家乡、年龄、成绩、BMI

skprimin 2021-07-11 00:19 原文

Java学生类

  • 成员变量:姓名、学号、学院学校、家乡、年龄、成绩、BMI
  • 成员方法:输出各大成员变量并简单计算
import java.text.DecimalFormat;

class Studin{
	 // print nameNB
	String Name;
	String getStudent() {
		return Name + " NiuBi Pro Plus Max";
	}
	
	String StudentID;
	String getStudentID(){
		return "Student ID: " + StudentID;
	}
	
//Classes of excellence for information technology   
	//Anhui University College of Computer Science
	String University;
	String College;
	String Class;
	String getUSC(){ 
		return  Class +", " + College + ", " +  University ;
	}
	
	
	// get his/her hometown
	String Province;
	String City;
	String District;
	String Town;

	String getHometown(){
		return  Town + " Town, " + District + " District, " + City + " City, " + Province + " Province";
		
	}
	
	//get her/his birth year
	int age; 
	int getBrithyear(){
		return 2021 - age;
	}
	// get his/her average grade
	float Java;
	float Python;
	float JavaScipt;
	float Go;
	float getGrade() {
		return (float) ((Java + Python + JavaScipt + Go) / 4.0);
	}	
}

class BMI{
	//get his/her height and weight then Calculation BMI
	double weight;
	double height;
	double getBMI() {
		return weight/height/height;
	}
	// judgment body status
	//double bmi;
	String getBodyStatus(double bmi) {
		if (bmi > 29.9) {
			return "肥胖Obesity";
		}
		else if (bmi > 25.0) {
			return "偏胖little Obesity";
		}
		else if (bmi > 18.5) {
			return "正常Normal";
		}
		else {
			return "偏瘦Thin";
		}
	}		
	
}

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Studin Fyz;
		Fyz = new Studin();
		
		Fyz.StudentID = "E01914163";
		String SID = Fyz.getStudentID();
		System.out.println(SID);
		
		//name student
		Fyz.Name = "YuZhen Feng";
		String Studen = Fyz.getStudent();
		System.out.println("Name:" +Studen);
		
		//University College Class
		Fyz.University = "** University";
		Fyz.College = "College of Computer Science";
		Fyz.Class = "Class of excellence for information technology";
		String Usc = Fyz.getUSC();
		System.out.println(Usc);
		
		// Hometown
		Fyz.Province = "AnHui";
		Fyz.City = "BoZhou";
		Fyz.District = "QiaoCheng";
		Fyz.Town = "NiuJi";
		String Hometown = Fyz.getHometown();
		System.out.println("Hometown: " + Hometown);
		
		//Birth year
		Fyz.age = 18;
		int Birth = Fyz.getBrithyear();
		System.out.println("Birthyear: "+Birth);
		
		// 0.00 set the number of decimal points   two decimal points
		DecimalFormat df = new DecimalFormat("0.00");
		
		//Grade
		Fyz.Java = 4.8f;
		Fyz.Python = 5.0f;
		Fyz.JavaScipt = 4.6f;
		Fyz.Go = 4.7f;
		float Grade = Fyz.getGrade();
		System.out.println("Grade: " + df.format(Grade));
		
		//BMI
		BMI FB;
		FB = new BMI();
		FB.weight = 60.2;
		FB.height = 1.9;
		double FyzBmi = FB.getBMI();
		System.out.print("BMI: " + df.format(FyzBmi));
		
		//BodyStatu
		String BodyStatu = FB.getBodyStatus(FyzBmi);
		System.out.println(" " + BodyStatu);
	}
}

运行结果:

Student ID: E01914163
Name:YuZhen Feng NiuBi Pro Plus Max
Class of excellence for information technology, College of Computer Science, ** University
Hometown: NiuJi Town, QiaoCheng District, BoZhou City, AnHui Province
Birthyear: 2003
Grade: 4.77       
BMI: 16.68 偏瘦Thin

推荐阅读