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 9 of 9

Thread: incompatible types

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Location
    malaysia
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default incompatible types

    here is my code :

    import java.io.*;
     
    public class assingmnt1
    {
    	//main program
    	public static void main (String[]args)
    	{
    		String studName[]={"Luqman Hakim Bin Hussein","Muhammad Irfan Bin Marzuki","Nur Hasniza Binti Illias","Nur Aqilah Asyikin Binti Mohd Jani","Nurul Syazareen Binti Md Said"};
    		int test1[] = {70,34,65,100,54};
    		int test2[] = {69,77,35,78,90};
    		int totalMarks[] = {0,0,0,0,0};
    		String status[]=new String[5];
     
    		CalculateMarks(test1,test2,totalMarks);
    		DetermineStatus(totalMarks,status);
    		Display(studName, totalMarks, status);
    	}
     
     
    	//calculate total marks
    	public static void CalculateMarks(int t1[], int t2[], int tmarks[])
    	{
    		for (int i=0;i<5;i++)
    		{
    			tmarks = (t1[i]*0.15) + (t2[i]*25/100);
    		}
    	}
     
     
    	//determined status
    	public static void DetermineStatus(int[] tmarks, String status[])
    	{
    		for(int i=0;i<5;i++)
    		{
    			if(tmarks[i] >=0 && tmarks[i] <=20)
    			{
    				status[i]="Cannot sit final exam";
    			}
    			if(tmarks[i] >=21 && tmarks[i] <=25)
    			{
    				status[i]="Must sit the 3rd test";
    			}
    			if(tmarks[i] >=26 && tmarks[i] <=35)
    			{
    				status[i]="Allow to sit the final exam";
    			}
    			if (tmarks[i] >=36 && tmarks[i] <=40)
    			{
    				status[i]="Excluded from sitting the final exam";
    			}
    		}
    	}
     
    	//display all
    	public static void Display(String studName[], int tmarks[], String status[])
    	{
    		for (int i=0; i<5;i++)
    		{
    			System.out.print ("\n Student Name : "+studName[i]);
    			System.out.print ("\n Total Marks : "+tmarks[i]);
    			System.out.print ("\n Student Status : "+status[i]);
     
    		}
    		System.out.println();
    	}
     
    }

    why i get incompatible types at line 25..?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: incompatible types

    Please post the full text of the error message that shows the found and required types.

    What line is line 25?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Location
    malaysia
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: incompatible types

    	//calculate total marks
    	public static void CalculateMarks(int t1[], int t2[], int tmarks[])
    	{
    		for (int i=0;i<5;i++)
    		{
    			tmarks = (t1[i]*0.15) + (t2[i]*25/100);
    		}
    	}


    the problem is at
    tmarks = (t1[i]*0.15) + (t2[i]*25/100);
    the error is "incompatible types"

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: incompatible types

    Please post the full text of the error message that shows what types the compiler found.
    For example:
    TestCode12.java:566: error: incompatible types
          x =   22;
                ^
      required: int[]
      found:    int


    What type is tmarks? The expression to the right of the = looks like a numeric value.
    Is tmarks a numeric variable?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Location
    malaysia
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: incompatible types

    tmarks is an array that will hold value total marks.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: incompatible types

    The assignment statement is trying to assign a numeric value to an array. The compiler doesn't allow that. If the variable to the left of the = is an array, then the value to the right of the = must be an array.

    Do you mean to assign a value to a slot in the array? Then use array notation with: []s like this:
    theArray[theIndex] = aValue;
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2013
    Location
    malaysia
    Posts
    5
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: incompatible types

    ermmm,
    i want like these :

    in the code, assign arrays named studName, test1, test2, totalMarks , status, and Display.

    then, calculate the test1 with weightage 15% and test 2 with weightage 25% and sum up.

    assign status using for the total marks.

    than display result using function Display()

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: incompatible types

    Did you understand what the problem with the code on line 25 was?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2013
    Location
    N. Ireland
    Posts
    29
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: incompatible types

    Quote Originally Posted by Norm View Post
    The assignment statement is trying to assign a numeric value to an array. The compiler doesn't allow that. If the variable to the left of the = is an array, then the value to the right of the = must be an array.
    required: int[]
    found:    int

    Norm has shown you the resolution. And the error code tells you what the problem is.

Similar Threads

  1. Incompatible types.
    By miller4103 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 12th, 2013, 08:36 PM
  2. Incompatible types
    By jadeclan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 26th, 2012, 07:09 AM
  3. Incompatible types
    By jadeclan in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 25th, 2012, 04:44 PM
  4. incompatible types!!
    By sneha343 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 30th, 2011, 05:48 PM
  5. Incompatible Types
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2010, 09:52 AM