Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: private couseName & grade

  1. #1
    Junior Member
    Join Date
    Mar 2014
    My Mood
    Thanked 0 Times in 0 Posts

    Default private couseName & grade

    i have errors in the "if" and both "else if"
    the compiler says "cannot convert from String to boolean and
    int to String


    1. Add two private instance variables,
    String courseName and char grade to this class.

    2. Add accessor and mutator methods for these
    instance variables.

    3. Add a method register which receives an integer data type and returns String data type according to the argument passed to it (“Math” for 1, “English” for 2, “No course” for any other input)

    what i have so far:

    package assignment9;
    public class BannerUser 
    	private int userId;
    	public int getUserId()  
    		return this.userId;
    	public void setUserId(int userId)  
        private String courseName; 
        public String getcourseName()  
        return this.courseName;
        public void setcourseName(String courseName) 
        private char grade;
        public char getGrade()
            return this.grade;
       String course;
        public String getCourse()
         if (course = 1)
         return "Math";
         else if(course = 2)
         return "English";
         else if (course != 1  !=2)
         return "No course";

  2. #2
    Join Date
    Oct 2013
    Manila, Philippines
    My Mood
    Thanked 64 Times in 61 Posts

    Default Re: private couseName & grade

    this statement else if (course != 1 !=2) made a compilation error, that is not a boolean expression and an invalid syntax in java.
    if you want to compare a course to 1 or 2, you can use logical operator || for conditional OR && for conditional AND etc.
    please refer to this link: Summary of Operators (The Java™ Tutorials > Learning the Java Language > Language Basics) or Java logical operators

  3. The Following User Says Thank You to dicdic For This Useful Post:

    ATB (April 6th, 2014)

Tags for this Thread