Home > Enterprise >  How can I print something based on the result of a boolean method?
How can I print something based on the result of a boolean method?

Time:03-30

I have two methods

*`public boolean validateMarks() {
    return (this.qualifyingMarks >= 65 && this.qualifyingMarks <= 100);
    }   
    public boolean validateCourseId() {
    return (this.courseId >= 1001 && this.courseId <= 1005);
    }`*

validateMarks(): Used to validate qualifying exam marks - qualifying marks is in the range of 65 to 100(both inclusive) validateCourseId(): Used to validate the course entered, based on the courseId - given in the table above calculateCourseFee(): Used to calculate the course fee after applying the discount.

So when is less than 65 print print "not elegible, you've failed" and when the course is not valid "course is not correct, please try again with the correct number of the course"

and this is my calculateCourseFee method

***if(this.validateMarks()) {
            this.courseFee = fee - (fee * discount);
            
            System.out.println("****Course Allocation Details****"   "\n"  
                    "Student Name: "   this.getStudentName()   "\n"   
                    "Course Id: "   this.getCourseId()   "\n"  
                    "Qualifying Exam Marks: "   this.getQualifyingMarks()   "\n"  
                    "Student's Registration Id: "   this.getRegistrationId()   "\n"  
                    "Total Course Fee: "   this.getCourseFee()   "\n"  
                    "Hostel Required: "   hostel);
        }else {
            System.out.println("wrong for marks ");
        }
        
        if(this.validateCourseId()) {
            this.courseFee = fee - (fee * discount);
            
            System.out.println("****Course Allocation Details****"   "\n"  
                    "Student Name: "   this.getStudentName()   "\n"   
                    "Course Id: "   this.getCourseId()   "\n"  
                    "Qualifying Exam Marks: "   this.getQualifyingMarks()   "\n"  
                    "Student's Registration Id: "   this.getRegistrationId()   "\n"  
                    "Total Course Fee: "   this.getCourseFee()   "\n"  
                    "Hostel Required: "   hostel);
        }else {
            System.out.println("Wroog for course");
        }
        ***

I make two different ifs for the two requirements, but everytime I run it, it prints the else statement to, even if marks is greather than 65... am I missing something?

Reviewing my code and tell me what am I missing or what am I doing wrong

CodePudding user response:

Code is correct. Did you right these methods in same class or diffrent classes?

CodePudding user response:

maybe qualifyingMarks is zero or another value, print qualifyingMarks in method "validateMarks",u will get the reason of your problem.

  • Related