Contact Info

sean [at] coreitpro [dot] com gpg key

Mastodon

sc68cal on Libera

Java Code #1

Been a while since I’ve coded in Java. Nearly four years. Last time I coded Java was in an AP Computer Science class. It was really, really, really difficult and really frustrating because it was the first programming class that I ever took, and the problem with the course that there was no instructor.

It was a self-taught course. In High School. I was totally not mature enough to do a self-study at that point in my life. It was a character building experience for me though.

Anyway, this is just a simple little program to print out “TEMPLE” horizontally using some for loops. I’m mostly proud of the drawE method because I did some serious decomposition to figure out how to take out all the redundant lines of code. It was a really fun “Eureka!” moment. I didn’t strip off all my clothes and start running through campus like Archimedes though.

//
//  templeprint.java
//  CIS81
//
//  Created by Sean Collins on 9/4/07.
//  Copyright 2007 Sean Collins. All rights reserved.
//
public class templeprint {
	public static void main(String args[]){
			drawT();
			drawE();
			drawM();
			drawP();
			drawL();
			drawE();
		}
	public static void drawT(){
		for (int i=0; i < 20; i++){
			System.out.print("T");
			}
		System.out.println();
		for (int i=0; i <5; i++){
			System.out.print("\t T \n");
		}

	}
	public static void drawE(){
		//Create a loop that for evens, prints the five E's, and for odds prints two and a carraige return
		for (int i=0; i < 5; i++){
			if (i % 2 == 1){
				for (int j=0; j < 5; j++){
				System.out.println("E");
				}
			}
			else{
				for (int k=0; k<5;k++){
					System.out.print("E");
				}
			}
		}
		System.out.println();
	}
	public static void drawM(){
		for (int i =0; i < 5; i++){
			if (i==0){
				System.out.println("MMMMMMMMM");
			}
			else
				System.out.println("M   M   M");
		}
	}
	public static void drawP(){
		for (int i=0; i< 6; i++){
			if (i ==0 || i == 2){
				System.out.println("PPPPPPPPPPPPP");
			}
			else if (i==1){
				System.out.println("P           P");
			}
		else
			System.out.println("P");
		}
	}
	public static void drawL(){
		for (int i =0; i < 8; i++){
			if (i==7){
				System.out.println("LLLLLLLLLLLLLLL");
			}
			else
				System.out.println("L");
		}
	}
}