为什么我在最后一行有语法错误?

时间:2016-03-28 16:26:36

标签: java compiler-errors syntax-error

//Caleb Howe Homework 5
public class MyStudent {

        public static void main(String[] args) {
        //Output print  
            Individual mine = new Individual();
            System.out.println("The last name of the "+ "student is " + mine.lname + " and the first name is " + mine.fname);
            System.out.println("The email address is " + mine.getemail());
            System.out.println("The UUID is " + mine.getUUID());
            System.out.println("-----------------------------------------");
            Individual Student2= new Individual("Jones", "John", "BITS", "Senior","3.5");
            System.out.println("The name of the Student is "+ Student2.fname+" "+Student2.lname);
            System.out.println("The email of the student is " +Student2.getemail());
            System.out.println("The GPA of the student is "+ Student2.gpa1);
            System.out.println("The major of the student is "+ Student2.qualification);
            System.out.println("The Student is a "+ Student2.year1);
            System.out.println("Press any key to continue . . .");
        }
}
        //class template for student
class Individual{
        //data for students
        String fname = "Caleb";
        String lname = "Howe";
        String qualification;
        String department;
        String year1;
        String gpa1;

        // constructor (bare minimum)
        public Individual(){

        }

        //constructor
        public Individual(String last, String first, String BBA, String year, String gpa){
            lname = last;
            fname = first;
            qualification = BBA;
            year1 = year;
            gpa1=gpa;
        }
        //constructor
        public String getemail(){
            String value = "default";
            int amount;
            value = fname;
            String email = "default";
            email = value.charAt(0)+lname+"@memphis.edu";
            return email;
        }
        //constructor
        public String getUUID(){
            String id = "";
            int number;
            number = (int) ((Math.random()*100)+1.00);
            id = number +fname.substring(0,1) + lname.substring(0, 1);
        }
}

当我编译它时,由于分号,它给我一个语法错误 无法弄清楚为什么,任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:3)

您的getUUID()方法定义为返回String,但您永远不会return。您可能想要添加return id;。此外,您通过不充当构造函数的方法有几个//constructor注释。

答案 1 :(得分:1)

整理缩进,为变量赋予有意义的名称。他们会在现在和将来帮助你做得更好。

getEmail和getUUID也不是构造函数,需要返回值。构造函数必须与类名相同。

相关问题