Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 25-04-2009
Member
 
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; 
          }
          }
     }
Reply With Quote
  #2  
Old 25-04-2009
Member
 
Join Date: Feb 2008
Posts: 194
Re: How to calculate substitution

Why does not it function? What is the error message?
Reply With Quote
  #3  
Old 25-04-2009
Member
 
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; 
     }
Reply With Quote
  #4  
Old 25-04-2009
Member
 
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. 
  }
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to calculate substitution"
Thread Thread Starter Forum Replies Last Post
Glitch in substitution and squad formation of FIFA 12: UEFA Euro 2012 Sib Bachchan Video Games 2 04-05-2012 11:29 AM
A substitution for HTC EVO GiveNTake Portable Devices 7 05-05-2011 07:01 AM
How to use Substitution function in TextEdit Jabeena Windows Software 5 17-02-2010 09:07 AM
How to Calculate Age Using SQL BALLARI Software Development 3 16-09-2009 03:14 PM
How to calculate Avg,Min and Max with SQL Plus B_Hodge Software Development 2 29-05-2009 01:08 PM


All times are GMT +5.5. The time now is 07:42 AM.