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

Thread: Solved.

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Solved.

    Solved.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,751
    My Mood
    Mellow
    Thanks
    233
    Thanked 711 Times in 697 Posts

    Default Re: Recording/Calculating Data Once.

    Phew! Thank you for taking the time to learn how to post code correctly.

    The best way to attack a "massive" project is to break it into small manageable pieces. Addressing your last 5 numbered items:

    1. Code efficiency comes with experience (practice, practice, practice), study, and through the advice of other more experienced, and hopefully wiser, programmers. You should be striving to make your code as simple as possible. I'm surprised you're still doing one-method programming for a project like this. You need to break the project into its parts (simplify) and code each of those parts in their own methods. Some of those methods might be shared by other parts. The only static method should be the main() method, and that should be reduced to a few lines at most.

    2. You say you don't know how to do input validation and recover when the input is invalid. Are those subjects yet to be taught, something to be thinking about in the months ahead? If they've already been taught, then you should go back and review those topics.

    3. Equations can be generalized (good for more than one specific case) by careful programming. A possible approach would be to initialize all values to an impossible value (a negative number?) and sum only positive values, counting as they are summed, dividing the sum by the count of positive numbers to obtain the average. There are other approaches. Do you know Arrays yet? How about the ArrayList class? Does your instructor have rules about only using what you've been taught in class, or are you allowed to learn outside the class, using what you've learned?

    4. I suggest using printf() to print formatted output, but there are other ways.

    5. Break the project into small, simple pieces. Attack each one, and test as you complete each piece or before, if possible. Don't wait to compile, run, and test when you have 4,000 lines of code.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    KaL (February 4th, 2014)

  4. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Recording/Calculating Data Once.

    1. The static method should be the main method. Got it, what should the main method entail? Variables only? Wouldn't variables declared in the main only exist in the main?

    2. They've already been taught, so was try and catch (guess I zoned out?). I've figured how to incorporate this into my code be reviewing them, thanks.

    3. We can use whatever we want, learnt outside or inside class so long as we get the program working like Goldsmiths UoL wants, Goldsmiths UoL doesn't care lol. We learnt arrays but not arrays list class yet. Still trying to figure out how to store the num of times the underlined value in the first post is entered(4.0 = number of exam marks, which can vary from 1 exam mark entered, to 4 exam marks entered).

    4. Thanks, but i think I'll stick with a parser.

    5. So far so good, I have psudocode that describes what each method does on paper, will be posting my code for each method on tuesday 11th Feb, if not sooner.

    Thanks again.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,751
    My Mood
    Mellow
    Thanks
    233
    Thanked 711 Times in 697 Posts

    Default Re: Recording/Calculating Data Once.

    1. A main() method could be as simple as:
        public static void main( String[] args )
        {
            new MyClass();
        }
    which passes control of the program's execution to the class' constructor. From there, the constructor takes over, initializing instance variables and calling other methods as needed, typically also passing control to another method after the variables have been initialized.

    2. Good. Try/catch is a way to go. Another approach might be simple 'if' statements. Whatever works.

    3. Consider an array of the same size as the possible number of inputs, say 7.

    int[] gradeArray = new int[7];

    initialized to negative values:
    for ( int grade : gradeArray )
    {
        grade = -1;
    }
    Store all grades entered in gradeArray, count the number of positive values in the array after the grades have been entered, and that number is how many grades have been entered.

    Or (probably easier), each time the user is given an opportunity to enter a grade, if a number > 0 is entered, increment the counter, numberOfGradesEntered, and add the number to a sumOfGradesEntered. After all grades have been entered, numberOfGradesEntered will be a count of the number of grades entered, and the average will be sumOfGradesEntered / numberOfGradesEntered.

    4. A parser? Parsers are for input. I thought you were talking about formatting output. An instance of NumberFormat? Not sure what you mean.

    5. Good approach and good luck. And you have a schedule. That's unusual but commendable. We'll be looking for it.

  6. The Following User Says Thank You to GregBrannon For This Useful Post:

    KaL (February 8th, 2014)

  7. #5
    Junior Member
    Join Date
    Feb 2014
    Posts
    4
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Recording/Calculating Data Once.

    1. If the main method has nothing in it, the program compiles but when it runs it does nothing lol.

    2. I'll weigh the two

    3. Pseduocode has to be written over -_-' thanks for the help though. You have no idea how mad I was driven by this problem in particular.

    4. Shit. Back to my notes :/

Similar Threads

  1. Recording Sound
    By mulligan252 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 1st, 2014, 12:45 AM
  2. Screen recording with java?
    By sci4me in forum Java Theory & Questions
    Replies: 1
    Last Post: May 16th, 2013, 10:58 PM
  3. RECORDING APP
    By louieseer in forum Android Development
    Replies: 3
    Last Post: May 13th, 2013, 07:40 AM
  4. Recording data , so you know whats next
    By ajw1993 in forum What's Wrong With My Code?
    Replies: 21
    Last Post: March 17th, 2013, 11:08 AM
  5. Replies: 3
    Last Post: May 25th, 2012, 08:48 PM