User:SamFisher1022/Java

From Homestar Runner Wiki

< User:SamFisher1022
Revision as of 20:14, 3 October 2007 by SamFisher1022 (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Hey juys. As you might have seen on my userpage, I'm learning Java in school. I tend to have obsessions when it comes to learning new stuff (this happened before when I was learning TI-BASIC), and I always want to learn at supersonic speed. I downloaded a nice Java IDE for home called JCreator, so now I can practice almost anytime. Below is sort of a journal of the Java source code I've written so far. If you have any hints or tips to make them better, give me a shout.

Contents

Class1

My first Java class compiled at home. All I could do, as you can see, was "println".

1  /**
2  * @(#)Class1.java
3  *
4  *
5  * @author 
6  * @version 1.00 2007/9/27
7  */
8 
9  public class Class1 
10 {
11     public static void main(String[] args)
12     {
13         System.out.println("Pikachu used Thundershock!");
14         System.out.println("A critical hit!");
15         System.out.println("It's super effective!");
16         System.out.println("The foe's Gyarados fainted! (surprisingly)");
17     }
18 }

StudentPoints

Learning the + operator was tough for us noobs. I fought with the compiler all class, and still couldn't get the code right. So I took the worksheets and sample code home and tried to compile it myself. With a little more thought, I got it to work (and was disappointed it's really so simple), then the problem became \t. I fought for another long while trying to get the columns to line up in the interpreter. Turns out spacing in the code does make a difference.

1 /**
2  * @(#)StudentPoints.java
3  *
4  *
5  * @author 
6  * @version 1.00 2007/10/1
7  */
8
9  public class StudentPoints
10 {
11     public static void main(String[] args)
12     	{
13     	// Prints a centered border and 1 blank line underneath
14     		System.out.println("\t <-------------------------------------->");
15     		System.out.println("\t | ==          Student Points        == |");
16     		System.out.println("\t <-------------------------------------->");
17    		System.out.println("");
18     	// Sets the table headings
19    		System.out.println("\tName      \t\tLab \t\tBonus \t\tTotal");
20    		System.out.println("\t----      \t\t--- \t\t----- \t\t-----");
21    	// Enter table data (Names and Scores)
22    		System.out.println("\tBob       \t\t34  \t\t20    \t\t" + (34 + 20));
23    		System.out.println("\tMary      \t\t37  \t\t22    \t\t" + (37 + 22));
24    		System.out.println("\tJoe       \t\t43  \t\t32    \t\t" + (43 + 32));
25    		System.out.println("\tGary      \t\t29  \t\t32    \t\t" + (29 + 32));
26    		System.out.println("\tJohn Kurt \t\t100 \t\t100   \t\t" + (100 + 100));
27     	}
28 }

ThingThing

This one's sort of odd. It's based on a TI game I'm writing called "Textventure." We were introduced to basic data types today, and I read ahead in the textbook to find operators for conditional statements just to get this started. As you can probably tell, it's very "just started." Right now, the code is broken. Line 18 seems to be the trouble, and the compiler's errors are "illegal start of type" and "<identifier> expected." "Illegal start of type" error also exists in line 23. As a noob, I don't know what this means or how to fix it. If you do, please help me out here.

1  // ****************************************************************************************************************
2  // ThingThing.java
3  // 
4  // Purpose == false
5  // ****************************************************************************************************************
6
7  public class ThingThing
8  {
9 	// Sets up variables: Str1, room
10 	// "|variable|" in comments refers to variables
11 	public static void main (String[] args)
12	{
13		String Str1 = "<Str1 is empty>";
14		int room = 22;
15	}
16	
17	// Displays room descriptions based on value of |room|
18	if (room == 22)
19	{
20		System.out.println("You are standing in a very plain field.");
21		System.out.println("There is a lone tree and lots of... nothing else.");
22      }
23	else
24	{
25		System.out.println("What have you done!?");
26		System.out.println("YOU'VE BLOWN UP ROOM 22!!");
27	}
28 }