r/learnjava • • Oct 08 '17

Programing Assignment Help

My professor doesn't teach us since she expects us to know how to do everything although I'm taking an intro class in java. Anyway, any help is appreciated. This is the assignment itself https://imgur.com/a/iT0Wq I have some ideas on how to do this problem but no way of actually knowing how to do them because of my professor. This is a link to the code I wrote on pastebin https://pastebin.com/GjUiZnnb. I tried to make one array with the entire input but the space is considered another input instead of a white space. There's a lot that needs to be done and I don't really know where to even start. Any help is super appreciated, thanks.

1 Upvotes

5 comments sorted by

1

u/RomanGuard Oct 09 '17 edited Oct 09 '17
  1. Use some kind of prompt "Enter number of students", "Enter name of student and grade" or whatever you decide to know where you are in the process and makes debugging a little easier.

  2. As the names and grades are entered, convert the string to a char array and store the inputs into a char array.

  3. Once that is done, using ascii codes count the number of letters using a int variable for letters and a different int variable for the numbers.

  4. If the inputs satisfy your requirements, pad the name and prefix some 0's according the int counters you used and print out the formatted string.

1

u/LocalPedo Oct 09 '17

I can’t do the first tip cause the program checker is very very specific on how it’s written, but thank you for everything else

1

u/RomanGuard Oct 09 '17

You can always remove the print out statements before you submit your code and it wont affect anything. Do however it makes sense to you.

1

u/smhanes Oct 08 '17

The number of students is the array size. Look at java arrays tutorials on how to create and add elements.

That number is also the number of times you'll run your loop. Each loop iteration should split the string on the space, calculate the length of each of the two substrings, pad accordingly, and then add them to the array you created.

This process of course will have to be modified in accordance with what is meant by input... Such as, are you actually given a text file, is input in the form of cli arguments passed in during runtime, is input requested from the command line during runtime..

1

u/mrs_frizzle Oct 09 '17

Your ppl variable tells you how many times to run the loop. Not sure why you incremented it on the next line?

For example, if I tell the program to expect 3 lines, I could write:

3 Student Grade Student2 Grade2 Student3 Grade3

Your program reads in the 3 and saves it as "ppl". So: while(ppl > 0) { Do your code

ppl-- }

Every time it finishes a line of input it will take one away from the loop counter, and stop with the last line of input. Not sure why you made each line an array?

You will use "printf" for the formatting, such as the padded zeros and alignment. Good luck.