Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
galvanize

Need help with assignment nearly finished

10 posts in this topic

I've got an assignment which I've completed for the basic compulsory section and im now doing the extra section to access more marks. The assignment is to put marks 0-100 and assign a star to a category depending on what mark you input. I've completed this part but now I have make it so it calculates the lowest, highest and average marks based on the inputs. I can paste the coding in here or if anyone would like to add my skype (galvanize_x) feel free to do so. Any help is appreciated and again this is only an extra so there is no rush. Thank you :)

 

EDIT: Ive done the average marks, now whats left is to show the lowest, highest and how many students passed the test (40 marks). I keep trying but it doesnt show anything when I run the project.

 

Assignment: http://pastebin.com/qkgZHufN

int first = 0;int second = 0;int third = 0;int forth = 0;int marks = 0;int m1 = 0;int m2 = 0;int m3 = 0;int m4 = 0;int star1 = 0;int star2 = 0;int star3 = 0;int star4 = 0;int totalmarks = 0;int totalstudents = 0;int min = 0;int max = 0;  Scanner input = new Scanner (System.in);System.out.println( "Enter number of marks ");    // TODO code application logic heremarks = input.nextInt(); while ( marks <= 100)        if (marks <=29)    {first = first + 1; m1 = m1 + marks;System.out.println(" Enter numbers of marks ");marks = input.nextInt();}     else if ( marks >= 30 && marks <= 39){second = second + 1;m2 = m2 + marks;System.out.println(" Enter numbers of marks ");   marks = input.nextInt();}     else if (marks >= 40 && marks <= 69)    {third = third + 1;m3 = m3 + marks;System.out.println(" Enter numbers of marks ");marks = input.nextInt();        }       else if  (marks >= 70 && marks <= 100)    {forth = forth + 1;m4 = m4 + marks;System.out.println(" Enter numbers of marks ");marks = input.nextInt();        }         System.out.print("0-29");while ( star1 < first){    System.out.print(" *");    star1 = star1 + 1;    } System.out.println("");                     System.out.print("30-39");        while (star2 < second)        {            System.out.print(" *");            star2 = star2 + 1;        }                System.out.println("");                System.out.print("40-69");        while ( star3 < third )        {            System.out.print(" *");            star3 = star3 + 1;        }        System.out.println("");                System.out.print("70-100");                while (star4<forth)        {            System.out.print(" *");            star4 = star4 + 1;        }        System.out.println("");                totalstudents = first+second+third+forth;        System.out.println(" There are " + totalstudents + " students in total " );        totalmarks = m1 + m2 + m3 + m4;        double average;        average = totalmarks/totalstudents;        System.out.println(" Average = " + average);               for (int x = 0; x<input.nextInt(); x++){                                                 totalmarks = input.nextInt();                          if (x == 0 || totalmarks > max){                             max = totalmarks;                          }                                       if (x == 0 || totalmarks < min){                             min = totalmarks;                          }                                 }                                   System.out.println("Highest value: " + max);                  System.out.println("Lowest value: " + min);            }    }
Edited by galvanize

Share this post


Link to post
Share on other sites

Can you also paste the actual assignment in here? Also it would help if you used code tags for your code, or pastebin instead of simply pasting it into your post.

Share this post


Link to post
Share on other sites

Can you also paste the actual assignment in here? Also it would help if you used code tags for your code, or pastebin instead of simply pasting it into your post.

Im sorry about that, ive done both of what youve asked me

Share this post


Link to post
Share on other sites

Can you copy and paste the assignment to pastebin? The Google Docs link you posted requires certain permission to access it.

Done

1 person likes this

Share this post


Link to post
Share on other sites

@galvanize

 

It's currently 3:18 over here and I have class in the morning, so I only did part one for now. Here you go:

 

MarksAssignment class

MarkRange enum

 

That is all you need for part 1 of your assignment, and should give you a strong foundation for the rest of it.

 

I'm going to get some sleep for tonight, but I'm on every day if you need more help.

Share this post


Link to post
Share on other sites

@galvanize

 

It's currently 3:18 over here and I have class in the morning, so I only did part one for now. Here you go:

 

MarksAssignment class

MarkRange enum

 

That is all you need for part 1 of your assignment, and should give you a strong foundation for the rest of it.

 

I'm going to get some sleep for tonight, but I'm on every day if you need more help.

Thank you I've done the basics and doing extras now :D and again thanks for your time for looking into this

Share this post


Link to post
Share on other sites

Having had a quick look at your code, here are a couple of suggestions I would make straight off the bat:

  • There are a number places that you could swap out code for short hand operators, such as:

    a ++; // increments a by one, this is the same as a = a + 1a += b; // adds b to a, this is the same as a = a + b
  • You seem to repeat yourself a fair amount - there's a design pattern called D.R.Y (Do Not Repeat Yourself), it's worth reading about, check it out on wikipedia: https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

  • I'd also maybe consider swapping out that massive if-else statement with something a little more eloquent, perhaps a switch that called a set of functions?

  • Final Calibur's solution is great, but definatly strikes me as code written by an experienced programmer, so if you're taking an entry level course, be careful when submitting the assignment - make sure you understand exactly what it's doing in case you're asked to explain some aspect of it.

Good Luck

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.