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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 4 of 4

Thread: Some help with boolean

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Some help with boolean

    Hello guys,

    I'm totally new to Java and I seek some help with this thing.
    I know it is too easy for you, but it's not the same for me as I'm playing with Java for 2 months only.

    I have this part of the code:

    public boolean setPercentages(int A, int B) {
        A = console.nextInt();
        B = console.nextInt();
     
    if (A + B == 100) {
        return true;
    }
    else {
        return false;    
    }

    I want to correct this code so that if the integers sum equals 100, then it returns "true" as well as the method assigns them to courseworkPercentage and examPercentage respectively, otherwise the program
    must return false.

    I'm confused now and I can not think a simple solution.
    Could you help me?

    Peter
    Last edited by JPetroSS; October 31st, 2010 at 08:10 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Some help with boolean

    What are courseworkPercentage and examPercentage? Where are they defined with respect to this function?

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Some help with boolean

    Quote Originally Posted by copeg View Post
    What are courseworkPercentage and examPercentage? Where are they defined with respect to this function?
    Sorry! Here's my code so far.....it's not that big so maybe you could help me

    import java.util.*;
     
    public class StudentInGradeBook {
        String lastName, firstName;
        int studentId;
        double courseworkGrade, examGrade, Grade;
        static double courseworkPercentage, examPercentage;
     
    public StudentInGradeBook (int I, String L, String F) {
        studentId = I;
        lastName = L;
        firstName = F;
    }
     
    public StudentInGradeBook() {
        studentId = 0;
        lastName = "Not defined";
        firstName = "Not defined";
    }
     
    public void setCourseworkGrade (double courseworkGrade) {
        courseworkGrade = courseworkGrade;    
    }
     
    public void setExamGrade (double examGrade) {
        examGrade = examGrade;
    }
     
    public int getStudentId() {
        return studentId;
    }
     
    public String getLastName() {
        return lastName;
    }
     
    public String getFirstName() {
        return firstName;
    }
     
    public double getCourseworkGrade() {
        return courseworkGrade;
    }
     
    public double getExamGrade() {
        return examGrade;
    }
     
    public double getGrade() {
        return Grade;
    }
     
    public double getCourseworkPercentage() {
        return courseworkPercentage;
    }
     
    public double getExamPercentage() {
        return examPercentage;
    }
     
    public double calcGrade;{
        Grade = (courseworkGrade * courseworkPercentage/100) + (examGrade * examPercentage/100);
    }
     
        static Scanner console = new Scanner(System.in);   
     
    public boolean setPercentages(int A, int B) {
        A = console.nextInt();
        B = console.nextInt();
     
    if (A + B == 100) {
        return true;
    }
    else {
        return false;    
    }
     
     
    }
    }

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Some help with boolean

    First, a question for you. Why are courseworkPercentage and examPercentage declared static? Do you really want them to have the same value for all instances of the class?

    db

Similar Threads

  1. Need help with what I believe is Boolean & add branching
    By JavaBeginner123 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 1st, 2010, 01:55 PM
  2. Boolean Value Not Changing
    By bosox960 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 21st, 2010, 02:11 PM
  3. boolean value in a simple loop (do-while)
    By chronoz13 in forum Loops & Control Statements
    Replies: 5
    Last Post: October 18th, 2009, 12:05 AM
  4. [SOLVED] Modification of Boolean function in Java program
    By lotus in forum Java SE APIs
    Replies: 4
    Last Post: July 10th, 2009, 10:15 AM
  5. Java operaton on boolean varibles
    By big_c in forum Java Theory & Questions
    Replies: 5
    Last Post: May 12th, 2009, 04:40 AM