Results 1 to 4 of 4

Thread: How to calculate substitution

  1. #1
    Join Date
    Nov 2008
    Posts
    1,221

    How to calculate substitution

    I created a class student, with 2 results for their exams. The first is Terminal marks and second is Exam marks. I created a method called average.

    Here is the code for this method:

    Code:
    / ** 
          * Calculates average of a list of integers 
          * / 
         public double average (List <integer> list) 
         { 
            double sum = 0.0; 
            for (int i = 0; i <list.size () i = i +1) 
            {
            sum = sum + list.get (i); 
            } 
            return sum/4; 
         }
    This method works great, when I type in display pane:

    Integer[] numberArray = {75, 59, 0, 70};
    Student.average (Arrays.asList (numberArray));

    51 is the result which is correct.

    My problem is to create the following method. I have to calculate the average of Terminal over Exam marks divided by 2. For example 51 + 64 / 2, which gives me the result of substitution of 57%. Here is my code:

    Code:
    / ** 
          * Calculates and sets the substitutionScore of the receiver 
          * / 
         public void calcSubstitutionScore ()    
         {
            for (int aScore:scores) 
            { 
               this. results. put (aScore, new HashSet<String> ( ) ) ;
            }
              for (String average: students. keySet ()) 
              { 
              for (String graded: this. results. get (average)) 
              { 
              this. results. get (graded). add (average) / 2; 
              }
              }
         }

  2. #2
    Join Date
    Feb 2008
    Posts
    194

    Re: How to calculate substitution

    Why does not it function? What is the error message?

  3. #3
    Join Date
    Nov 2008
    Posts
    1,221

    Re: How to calculate substitution

    It gives me a lot of syntax errors. For example for the line:

    this.results.get (graded). add (average)/2;

    It makes me: not a statement.

    For the line:

    for (int aScore : scores)

    It makes me: cannot find symbol - variable score

    I have in a class called Student: private int substitutionScore; Having 2 methods:

    Code:
    / ** 
          * Sets the substitutionScore of the receiver to aScore
          * / 
         private void setSubstitutionScore (int aScore) 
         {
            this. substitutionScore = aScore; 
         }
    
       / ** 
          * Returns the substitutionScore of the receiver 
          * / 
         public int getSubstitutionScore () 
         { 
            return this. substitutionScore; 
         }

  4. #4
    Join Date
    Feb 2008
    Posts
    194

    Re: How to calculate substitution

    In Java the use of the terms subject to different rules of visibility. It is not enough that you sent in your head, and so the Java will work.

    As a very simple example:

    Code:
    {// Block 
       {// Another block 
         int quantity; // I declare my variable here 
      
        quantity = 45 // good: the variable quantity is declared in the same block 
        Quantity = 45 // syntax error here: quantity is not EQUAL to Quantity in Java 
       } 
       quantity = 45 // syntax error here: quantity is not declared in this block. 
      }

Similar Threads

  1. Replies: 2
    Last Post: 04-05-2012, 11:29 AM
  2. A substitution for HTC EVO
    By GiveNTake in forum Portable Devices
    Replies: 7
    Last Post: 05-05-2011, 07:01 AM
  3. How to use Substitution function in TextEdit
    By Jabeena in forum Windows Software
    Replies: 5
    Last Post: 17-02-2010, 09:07 AM
  4. How to Calculate Age Using SQL
    By BALLARI in forum Software Development
    Replies: 3
    Last Post: 16-09-2009, 03:14 PM
  5. How to calculate Avg,Min and Max with SQL Plus
    By B_Hodge in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 01:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,801,387.37555 seconds with 17 queries