Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Question somebody help me please.

    i've wrote a coding, it can compile, but the result is something at marks area. its suppose come out with the difference values, but it display number 0 only.

    Java Code:
    import java.io.*; 
    import java.lang.String;
    
    
    
    
    public class Assignment1 {
    	public static void main(String[] args) {
    		
    		String[] studName = {"Aminah Binti Samad", "Putra Bin Abdul", "Muadz Bin Kassim", "Kaisara Binti Dollah", "Rahaman Bin Ismail"};
    		int test1[] = {90, 45, 78, 80, 60};
    		int test2[] = {40, 80, 78, 95, 93};
    		int Marks[] = {0, 0, 0, 0, 0};
    		String[] status = new String[5];
    		
    		CalculateMarks(test1, test2, Marks);
    		DetermineStatus(Marks, status);
    		Display(studName, Marks, status);
    	}
    	
    	public static void CalculateMarks(int test1[], int test2[], int Marks[])
    	{
    		for(int i = 0; i < 5; i++)
    		{
    			
    			
    			test1[i] = (15 / 100) * test1[i];
    			test2[i] = (25 / 100) * test2[i];
    			
    			Marks[i] = test1[i] + test2[i];
    			
    		
    		
    		return;
    		}
    	}
    	
    	public static void DetermineStatus(int Marks[], String[] status)
    	{
    		for (int i = 0; i < 5; i++)
    		{
    		if( Marks[i] >= 0 ||  Marks[i] <= 20)
    			status[i] = "Cannot sit the final exam";
    		else if( Marks[i] >= 21 ||  Marks[i] <= 25 )
    			status[i] ="Must sit the 3rd test";
    		else if( Marks[i] >= 26 ||  Marks[i] <= 35 )
    			status[i] ="Allow to sit the final examination";
    		else if( Marks[i] >= 36 ||  Marks[i] <= 40 )
    			status[i] ="Excluded from sitting the final examination";
    		}
    		return;
    		
    	}
    	
    	public static void Display(String studName[], int Marks[], String[] status)
    	{
    		for(int i = 0; i < 5; i++)
    		{
    		System.out.print("\n Student Name : " +studName[i]);
    		System.out.print("\n Student Marks : " +Marks[i]);
    		System.out.print("\n Student Status : " +status[i]);
    		System.out.print("\n\n\n");
    		}
    		
    		return;
    	}
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: somebody help me please.

    Lines #27 and #28 perform integer division and with your numbers the result will be zero.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: somebody help me please.

    so i should change it to double?

  4. #4
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: somebody help me please.

    i've change it to double, but its still display the 0 value

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  6. #6
    Join Date
    Mar 2013
    Posts
    4
    Rep Power
    0

    Default Re: somebody help me please.

    public class Assignment1 {
    public static void main(String[] args) {

    String[] studName = {"Aminah Binti Samad", "Putra Bin Abdul", "Muadz Bin Kassim", "Kaisara Binti Dollah", "Rahaman Bin Ismail"};
    double test1[] = {90, 45, 78, 80, 60};
    double test2[] = {40, 80, 78, 95, 93};
    double Marks[] = {0, 0, 0, 0, 0};
    String[] status = new String[5];

    CalculateMarks(test1, test2, Marks);
    DetermineStatus(Marks, status);
    Display(studName, Marks, status);
    }

    public static void CalculateMarks(double test1[], double test2[], double Marks[])
    {
    for(int i = 0; i < 5; i++)
    {




    Marks[i] = test1[i]*0.15 + test2[i]*0.25;



    return;
    }
    }

    public static void DetermineStatus(double Marks[], String[] status)
    {
    for (int i = 0; i < 5; i++)
    {
    if( Marks[i] >= 0 || Marks[i] <= 20)
    status[i] = "Cannot sit the final exam";
    else if( Marks[i] >= 21 || Marks[i] <= 25 )
    status[i] ="Must sit the 3rd test";
    else if( Marks[i] >= 26 || Marks[i] <= 35 )
    status[i] ="Allow to sit the final examination";
    else if( Marks[i] >= 36 || Marks[i] <= 40 )
    status[i] ="Excluded from sitting the final examination";
    }
    return;

    }

    public static void Display(String studName[], double Marks[], String[] status)
    {
    for(int i = 0; i < 5; i++)
    {
    System.out.print("\n Student Name : " +studName[i]);
    System.out.print("\n Student Marks : " +Marks[i]);
    System.out.print("\n Student Status : " +status[i]);
    System.out.print("\n\n\n");
    }

    return;
    }
    }

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: somebody help me please.

    In your method CalculateMarks you have a return statement in the body of a for-loop.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: somebody help me please.

    farahinsamsudin, please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    tamilarasi is offline Member
    Join Date
    Nov 2012
    Location
    India
    Posts
    70
    Rep Power
    0

    Default Re: somebody help me please.

    you made some mistake on your code like

    you create CalculateMarks function like below...

    Java Code:
     public static double[]  CalculateMarks(double test1[], double test2[], double Marks[])
        {
        for(int i = 0; i < 5; i++)
        {
    
    
    
    
        Marks[i] = test1[i]*0.15 + test2[i]*0.25;
    
    
    
       
        }
         return Marks;
        }
    Then you call this method like this..

    Java Code:
    Marks=CalculateMarks(test1, test2, Marks);
    No this will be works Because each time you the array but not return anything.

    So your output got the value what you create the array..

    that's only got this value double Marks[] = {0, 0, 0, 0, 0};
    Regards
    Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •