fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Student{
  6. int H;
  7. int W;
  8. float BMI;
  9.  
  10. Student(){
  11. H=180;
  12. W=68;
  13. Name="Jack";
  14. }
  15.  
  16. Student(int H,int W){
  17. this.H=H;
  18. this.W=W;
  19. }
  20. Student(String Name,int H,int W){
  21. this.Name=Name;
  22. this.H=H;
  23. this.W=W;
  24. }
  25. void setName(String Name){
  26. this.Name=Name;
  27. }
  28. void show(){
  29. System.out.println("學生:"+Name+",身高:"+H+"公分,體重:"+W+"公斤,BMI:"+BMI);
  30. }
  31. void calculate(){
  32. BMI=W/((H/100.0f)*(H/100.0f));
  33. }
  34. }
  35.  
  36.  
  37.  
  38. class Ideone
  39. {
  40. public static void main (String[] args) throws java.lang.Exception
  41. {
  42. Student s1 = new Student(173,80);
  43. s1.setName="Mary";
  44. s1.calculate();
  45. s1.show();
  46.  
  47. Student s2 = new Student("Jennifer",167,53);
  48. s2.calculate();
  49. s2.show();
  50.  
  51. Student s3 = new Student();
  52. s3.calculate();
  53. s3.show();
  54.  
  55. }
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:44: error: cannot find symbol
		s1.setName="Mary";
		  ^
  symbol:   variable setName
  location: variable s1 of type Student
1 error
stdout
Standard output is empty