Favourite early piece of code you wrote?

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 22680 Views - Last Post: 13 December 2012 - 10:52 AM

#1 denisonjava  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 11-March 11

Favourite early piece of code you wrote?

Posted 28 March 2011 - 05:32 AM

Well I'm quite a noobie at Java still but I was just browsing through my folders on my comp and found this, it's from my first 2 months in college and I just felt so proud of it at the time.
It's supposed to be a hotel reservation thingy, looking at it now it's pretty basic haha, no GUI or file handling or such... but it still makes me proud haha.
here's mine :)
post yours too.
import java.io.*;
public class SuperHotel {
public static void main (String[]args) throws IOException {

double Single=75;
double Double=140;
double Triple=160;
double Early=12.5;
double Carte=20;
char option2;
char option3;
char option;
int i=0;
double sum;
int num=1;
int num1=1;
double sum1;

BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in));

do
{
	System.out.println("*************************");
	System.out.println("*                       *");
	System.out.println("* Welcome to SuperHotel *");
	System.out.println("*                       *");
    System.out.println("*************************");
	System.out.println(" ");
	System.out.println("For a Restaurant Reservation, press 'r'");
	System.out.println("For a Room Reservation, press 'b'");
	System.out.println("To Exit, press 'x'");

    option = (char) kbd.read();
    kbd.readLine ();

	if (option == 'r')
   	{
	   	System.out.println("For the Early Bird at 12.50 pps, press 'e'");
	   	System.out.println("For a la Carte at 20 pps, press 'a'");
        option2 = (char) kbd.read();
        kbd.readLine ();
    	if(option2 == 'e')
    	{
			System.out.println("How many people will be eating?");
			num=Integer.parseInt(kbd.readLine());
			sum=num*Early;
		    System.out.println("The total cost will be "+sum);
	    }
        if(option2 == 'a')
		{
	    System.out.println("How many people will be eating?");
	    num=Integer.parseInt(kbd.readLine());
		sum=num*Carte;
		System.out.println("The total cost will be "+sum);
	    }


    }

	if (option == 'b')
	{
		System.out.println("For a Single Room, press 's'");
		System.out.println("For a Double Room, press 'd'");
		System.out.println("For a Triple Room, press 't'");
		option3 = (char) kbd.read();
        kbd.readLine ();
        if(option3 == 's')
        {
			System.out.println("How many nights will you be staying?");
			num1=Integer.parseInt(kbd.readLine());
			sum1=num1*Single;
		    System.out.println("The total cost of a Single for "+num1+" person(s) cost will be "+sum1);
		}
		if(option3 == 'd')
		{
            System.out.println("How many nights will you be staying?");
			num1=Integer.parseInt(kbd.readLine());
			sum1=num1*Double;
		    System.out.println("The total cost of a Double for "+num1+" person(s) will be "+sum1);
		}
		if(option3 == 't')
		{
            System.out.println("How many nights will you be staying?");
		    num1=Integer.parseInt(kbd.readLine());
			sum1=num1*Single;
		    System.out.println("The total cost of a Triple for "+num1+" person(s) will be "+sum1);
        }




    }




}while(option != 'x');

}
}


Thanks for reading,
Denis

Is This A Good Question/Topic? 0
  • +

Replies To: Favourite early piece of code you wrote?

#2 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1907
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: Favourite early piece of code you wrote?

Posted 29 March 2011 - 12:46 AM

My favourite was a utility class with some handy trig functions, stuff like rotating points around a centre. I used it in quite a few projects for some graphics stuff. I was a bit sad the day I found the AffineTransform class in the Java API since it surpassed my work in functionality, but I did dig out that old class a few months ago for a project I was doing.
Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2858
  • View blog
  • Posts: 10,962
  • Joined: 15-July 08

Re: Favourite early piece of code you wrote?

Posted 29 March 2011 - 02:58 AM

I think that my favorite was a piece of PHP code that highlighted Java syntax. However, I quickly found that doing that on the server side is expensive, and so I switched to Javascript code tagging. But for a short time, it was all PHP.

It was my first non-web-displayable PHP file (and instead was a module).

Since this is the Java Programmers section though, I guess I'll say that my favorite piece of code that I wrote were some of the classes for my DreamInCode Client. However, it also had some of my ugliest code. To look at that code, connect with SVN and download.
Was This Post Helpful? 0
  • +
  • -

#4 Kleptako  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 14-February 11

Re: Favourite early piece of code you wrote?

Posted 29 March 2011 - 11:16 AM

a console RPG game. took like 5 days to complete it
Was This Post Helpful? 0
  • +
  • -

#5 denisonjava  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 11-March 11

Re: Favourite early piece of code you wrote?

Posted 30 March 2011 - 02:18 AM

View PostKleptako, on 29 March 2011 - 11:16 AM, said:

a console RPG game. took like 5 days to complete it


What was the game? Care to give any details, name, when it came out? etc.

Thanks for the post,
Denis
Was This Post Helpful? 0
  • +
  • -

#6 Kleptako  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 14-February 11

Re: Favourite early piece of code you wrote?

Posted 30 March 2011 - 07:21 AM

View Postdenisonjava, on 30 March 2011 - 02:18 AM, said:

View PostKleptako, on 29 March 2011 - 11:16 AM, said:

a console RPG game. took like 5 days to complete it


What was the game? Care to give any details, name, when it came out? etc.

Thanks for the post,
Denis


Its just something i made for my self to have fun:)

btw, its not console like Xbox and Ps3, its the cmd console:D
Was This Post Helpful? 0
  • +
  • -

#7 Bellum  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 53
  • Joined: 04-February 09

Re: Favourite early piece of code you wrote?

Posted 03 June 2011 - 12:30 PM

I wrote a text tic tac toe game with a simple AI in Python, which I was more proud of than I deserved and that I played more times than was probably healthy. :P

...

A Swing tic tac toe game is definitely gonna be my next project. :lol:
Was This Post Helpful? 0
  • +
  • -

#8 kamran619  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 74
  • Joined: 05-July 11

Re: Favourite early piece of code you wrote?

Posted 05 July 2011 - 06:18 PM

View PostBellum, on 03 June 2011 - 12:30 PM, said:

I wrote a text tic tac toe game with a simple AI in Python, which I was more proud of than I deserved and that I played more times than was probably healthy. :P

...

A Swing tic tac toe game is definitely gonna be my next project. :lol:


I am trying to make a swing tic tac toe game with AI as well! I don't exactly know how to make the AI functionality though. I think for an 'easy' difficulty level in tic tac toe you can make the computer pick randomly from the board, but how do you make a difficult computer with adequate AI in tic tac toe?
Was This Post Helpful? 0
  • +
  • -

#9 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 1907
  • View blog
  • Posts: 3,953
  • Joined: 11-December 07

Re: Favourite early piece of code you wrote?

Posted 06 July 2011 - 01:22 AM

For Tic Tac Toe, you can make a game tree of all the possible moves. The computer can pick the ones that are most likely to lead to a win.
Was This Post Helpful? 0
  • +
  • -

#10 Mila  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 33
  • View blog
  • Posts: 193
  • Joined: 28-October 06

Re: Favourite early piece of code you wrote?

Posted 06 July 2011 - 08:00 AM

I took a Principles of Programming class my third semester of university. For the section where we learned about threads we had to write a Java version of the game "snake". (The one where you're a little snake and you're moving around the board eating apples and every time you eat an apple you grow, but you die if you touch yourself or the walls.) For extra credit and because I was bored I wrote in an AI so you could play against the computer. Unfortunately I made the AI a little too good and it's just about impossible to win.
Was This Post Helpful? 0
  • +
  • -

#11 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Favourite early piece of code you wrote?

Posted 06 July 2011 - 03:36 PM

Barring all the simple programs I made, one of my first proper projects was using Lego Mindstorms. I built a robot car and applied various sensors to it. I then made it drive autonomously between 2 points using gps navigation. It also had a load of kool AI built into it, and various other features using various sensor types. At the moment, I am in the midst of developing a 100% java built virtual world with a client, server, and common state. I am using Open Wonderland as my base, and buiulding up from there. Once I get deeper into this, I plan to take the robot I created above and integrate it within the virtual world. So in essense, I want a real world object to control a virtual world object. The virtual world will be mapped to represent the real world, and sensor data from the robot will be sent to the virtual robot, and the two will perform the exact same movements and actions. Should be great fun to do and I cant wait to get further into it.
Was This Post Helpful? 1
  • +
  • -

#12 stackoverflow  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 545
  • Joined: 06-July 11

Re: Favourite early piece of code you wrote?

Posted 06 July 2011 - 09:10 PM

The first program I wrote in Java was a GUI based die roller. I called it Droller. You can see the source here on my Git, or check out the jar here.

I basically wrote it while reading a Java textbook on my own. The textbook was Java Foundations. I got inspired when I seen the simple GUI example which basically had a jButton which output an integer in a text field. I started to hack away and made Droller. I kept adding a little functionality-- like a log/history list of past rolls etc. I really liked this little program!
Was This Post Helpful? 0
  • +
  • -

#13 coder364  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-July 11

Re: Favourite early piece of code you wrote?

Posted 07 July 2011 - 11:36 PM

My favoruite peice of code was my first ever GUI application on java, An appointment maker.

Even after i submitted it i could never believe i made that in a short period of time. :)

Its always nice to check the early codes , gives a nostalgic feeling ...
Was This Post Helpful? 0
  • +
  • -

#14 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Favourite early piece of code you wrote?

Posted 09 July 2011 - 04:28 PM

my favorite program that I wrote was in my intro to CSIT class. We had a section in the book about basics of programming. As an assignment we were to use pencil and paper and control a robot to do various things. The robot had 8 commands that it could do and could only support 32 lines of code. So with those 8 functions we were supposed to do a few things. Well after about 1 hour of thinking in my head how to do what the robot was supposed to do, i got tired of it and used my java "skills" (if you could call it that) to make a GUI that displayed the random room that the robot was in. It then had another frame that said what the robot was doing, what his current instruction was, what his previous one was, what his next one was, if his arm was up, if his light was on and a few other things (mainly for debugging)..

I was so proud of it because in class the teacher was like "turn in your assignments" and I handed in a flash drive and everyone else in class didn't get the assignment and so didn't do it. I was the only one. So we put my program up on the projector and used it to "test" other people's code for the robot. Which no one got right except me. Funny thing is is that there was a guy who sat behind me and said that he could teach the class because he was HTML programmer. LOL! he had me look at his code and it was just a web page builder program all click and drag. Sooooo hard to read. Some people are nerds..and some people are wanna be nerds which is even worse! I like being just a nerd.
Was This Post Helpful? 0
  • +
  • -

#15 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 251
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Favourite early piece of code you wrote?

Posted 13 August 2011 - 04:35 AM

My first year learning Java I wrote an ultra-simple blackjack game, which I've always looked back fondly on.
Posted Image

After coding in Java for about a year I wrote an RSS/Atom reader which I fully intended to update when JavaFX came out, but then I realized...who uses an RSS reader anymore?
Posted Image

This post has been edited by Programmist: 13 August 2011 - 04:37 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2