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

Thread: Struggling with Java counter

  1. #1
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Struggling with Java counter

    ythtyhyt


  2. #2
    Member
    Join Date
    Apr 2012
    Posts
    151
    Thanks
    0
    Thanked 22 Times in 22 Posts

    Default Re: Struggling with Java counter

    Well from what you have given the problem is still a little unclear, but looking at your computeResult method I can see a few things that might be throwing it off

    Your for loop is told to loop while l is greater than or equal to 5, which will never happen since you initialize it to 0

    Also, you are using results => 34, which is not valid java code. results is an array of integers and as such does not directly evaluate to an integer. The => symbol is also incorrect.
    This same issue is found when comparing results == "Compensation fail".

    On a side note, when comparing to a string, you must use the .equals() method rather than the primitive ==

  3. #3
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Struggling with Java counter

    So basically i'm screwed : ( . Can't believe i've been doing this thing since 11am and it's now 3.30am =/

  4. #4
    Member
    Join Date
    Apr 2012
    Posts
    151
    Thanks
    0
    Thanked 22 Times in 22 Posts

    Default Re: Struggling with Java counter

    No, that's not what I was saying at all.

    If you have any other more specific questions feel free to ask

  5. #5
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Struggling with Java counter

    atm i've got and thanks, appreciated.

    public static void computeResult(String results, int[] examMarks, int[] cwMarks) {
     
    		int count = 0;
    		int count2 = 0;
    		int count3 = 0;
     
    		for (int l = 0; l >= 5; l++)
     
    		{
     
    			if (cwMarks[l] < 35 || examMarks[l] < 35){
    				count = count + 1;
    				results= "You Failed!";
    			}
    			else if (cwMarks[l] < 35 || examMarks[l] < 35){
    					count2 = count2 + 1;
    					results="You passed by compensation!";
    			}
    				else if
    					(cwMarks[l] < 35 || examMarks[l] <35){
    				   count3 = count3 + 1;
    					results="You passed year 1!";
     
     
    			}
    		}

  6. #6
    Member
    Join Date
    Apr 2012
    Posts
    151
    Thanks
    0
    Thanked 22 Times in 22 Posts

    Default Re: Struggling with Java counter

    So is this solution working or are you still having issues?

  7. #7
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Struggling with Java counter

    i

    --- Update ---

    I'm still having issues. For this method my aim is :

    "A method computeResult that, an array of student exam and coursework marks, returns a Stage Result for that student (again you may pass 2 arrays rather than one if you prefer). You may assume each module is weighted equally which is true for Stages 1 and 2 modules."

    It basically ignores method 2 and just runs method 1. Technically it doesn't ignore it because if i put system.out.println("fwefewfewfewF"); in method 2 it'd show up. But i mean with the information i'm using atm it's just having no effect. I know the numbers aren't accurate atm for the if statement i've created but i just want to get it actually functioning for now. Sorry if my wording is terrible, i've been doing this for around 15-17 hours straight.. =/

  8. #8
    Member
    Join Date
    Apr 2012
    Posts
    151
    Thanks
    0
    Thanked 22 Times in 22 Posts

    Default Re: Struggling with Java counter

    Well as I mentioned in the first reply, your for statement never runs the way you have it setup.
    The logic behind it is saying to loop while your counter variable l is greater than or equal to 5. Since you start this variable at 0, which is not greater than or equal to 5, it never runs.

Similar Threads

  1. Replies: 4
    Last Post: November 6th, 2013, 04:26 AM
  2. Java Cupcake Counter Help
    By Hawks in forum What's Wrong With My Code?
    Replies: 12
    Last Post: February 20th, 2013, 01:47 PM
  3. Struggling with Java :o
    By Jabdennel in forum Java Theory & Questions
    Replies: 1
    Last Post: May 30th, 2011, 09:08 PM
  4. Hi from UK, Struggling with java!
    By Sneak in forum Member Introductions
    Replies: 6
    Last Post: December 14th, 2009, 08:39 AM
  5. Details about 'CopyTo' of Arrays in Java
    By Fendaril in forum Collections and Generics
    Replies: 18
    Last Post: November 13th, 2008, 07:31 AM