Why the things in this code mean what they mean,an incomplete step and documentation help
Recently I got major help from tutor but I forget some of the stuff he said and (unlike the next time tomorrow) I didn't have a recorder on me at the time so I can't go back and refer to what he was saying -_- .
I'd just like explanations to understand this.See even though my tutor graciously commented to the side what each line of code does I don't think I still know why what is there is there and how each statement works.
This is the nearly done code.
Code :
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner; // brings in library to read keyboard input
//import java.lang.String;
public class Lab1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner usernum=new Scanner (System.in); //create object for keyboard input
System.out.print("enter number of groups "); // ask user for a number
int userInput = usernum.nextInt(); // takes keyboard input and put into variable userInput
System.out.print("ASCII 1-127\n"); // print title
for (int groups=0; groups<=127; groups=groups+1){ // loop until the counter is over userInput number
String dec=Integer.toString(groups); //convert to dec
String hex=Integer.toHexString(groups); //convert dec to hex
char ascii=(char)groups; //convert dec to ascii
System.out.print(dec+" "+hex+" "+ascii+" "); // print on screen
if ((groups % userInput)==0) {
System.out.print("\n");
}
}
System.out.print("\n");
}
}
This is the nearly done code.What questions are left of this is a step that says that "each group of small columns will be 8 chars wide and properly aligned for values less than 6".What does that mean when you got something like this?.
Re: Why the things in this code mean what they mean,an incomplete step and documentation help
What does the code print out when it executes?
What is the purpose of the program?
It looks like it gets some input from the user, does some computations and prints out something. That's a common thing for a program.
Re: Why the things in this code mean what they mean,an incomplete step and documentation help
Quote:
Originally Posted by
Norm
What does the code print out when it executes?
What is the purpose of the program?
It looks like it gets some input from the user, does some computations and prints out something. That's a common thing for a program.
What this code prints out when it executes is (when you type in a number from 0-127) the ASCII code table up until the number you typed in.Now that I'm speaking about that for some reason it's not doing that and just printing out the 127 ASCII table figures -_-.Seems like I might need help with that too `_` .
Also,no offense but isn't that something that could be figured out just by looking at the code '~' ?.
Re: Why the things in this code mean what they mean,an incomplete step and documentation help
Quote:
by looking at the code '~' ?.
There are many subtle things in programming that can be missed. Why take a chance when it's so easy to compile and execute code to see what it does. And it's a lot easier and there is not doubts about what the code does. The printout shows it.
Can you post the output for the program?
Quote:
the ASCII code table up until the number you typed in
Are you sure? Execute the program with some different input values to see what it does.
Quote:
printing out the 127 ASCII table figures
Which is it? ASCII codes up to the number entered
or 127 codes?
3 Attachment(s)
Re: Why the things in this code mean what they mean,an incomplete step and documentation help
Quote:
Originally Posted by
Norm
There are many subtle things in programming that can be missed. Why take a chance when it's so easy to compile and execute code to see what it does. And it's a lot easier and there is not doubts about what the code does. The printout shows it.
Thanks it makes sense.
Quote:
Originally Posted by
Norm
Can you post the output for the program?
Are you sure? Execute the program with some different input values to see what it does.[/QUOTE]
Hopefully these snippings of the screen output help.Sorry the sizes (i'd change them ASAP if I knew how) but the numbers are 2,23 and 123
Attachment 1715Attachment 1716Attachment 1717
Quote:
Originally Posted by
Norm
Which is it? ASCII codes up to the number entered
or 127 codes?
it generates ASCII codes so long as you don't go beyond the number 127.
Re: Why the things in this code mean what they mean,an incomplete step and documentation help
What are your questions now?
Quote:
go beyond the number 127.
What happens then?
Re: Why the things in this code mean what they mean,an incomplete step and documentation help
Quote:
Originally Posted by
Norm
What are your questions now?
What happens then?
Oh it's all good now man,thanks 4 your help.Now I just got a question about how to do good java documentation which is an easy quarter's worth of my mark.Would you (or anyone else) be able to show me some a/o a good example of well done java documentation in a program's code would you?
Re: Why the things in this code mean what they mean,an incomplete step and documentation help
Quote:
good example of well done java documentation in a program's code
That will be very very hard to find looking at student code on the forums. I see a well documented program about once a month.
Look at the source code that comes with the JDK. It's in a zip file: src.zip