Jump to content

Skateboard Object

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Cruel Hand

Cruel Hand

    Learning Programmer

  • Members
  • PipPipPipPip
  • 109 posts
  • Programming Language:Java
  • Learning:Java, Visual Basic .NET
I was bored just now and I like skateboarding so I decided to make a skateboard object. Can anyone tell me if it looks good or could be improved or anything? thanks :)

lets assume that in real life, you must be riding a skateboard to do a trick.

import java.util.*;


public class tuna{

	String brand;

	Boolean isOn = false, isMoving = false;

	Random r = new Random();

	int trickChance = 0;

	

	public tuna(String brand){

		this.brand = brand;

	}

	public void getOn(){

		System.out.println("You get on the skateboard.");

		isOn = true;

	}

	public void ride(){

		if(isOn == true){

			System.out.println("You ride the skateboard.");

			isMoving = true;

			}

		else 

			System.out.println("You must be on the skateboard first.");

	}

	public void ollie(){

		if(isMoving == true){

			trickChance = 1 + r.nextInt(100);

			if(trickChance < 90){

				System.out.println("You successfully ollie!");

			}else{

				System.out.println("You try to ollie and crash.");

			

			}

		}

		else{

			System.out.println("You must be riding the skateboard to do a trick.");

		}

	}

	public void kickFlip(){

		if(isMoving == true){

			trickChance = 1 + r.nextInt(100);

			if(trickChance < 75){

				System.out.println("You successfully kick flip!");

			}else{

				System.out.println("You try to kick flip and crash.");

			}

		}

		else{

			System.out.println("You must be riding the skateboard to do a trick.");

		}

	}

	public void popShoveit(){

		if(isMoving == true){

			trickChance = 1 + r.nextInt(100);

			if(trickChance < 80){

				System.out.println("You successfully perform a pop shove it!");

			}else{

				System.out.println("You try to perform a pop shove it and crash.");

			}

		}

		else{

			System.out.println("You must be riding the skateboard to do a trick.");

		}

	}

}

	


Edited by Cruel Hand, 07 December 2011 - 12:20 PM.
spelling error


#2
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
I don't know a lot about skateboard (pretty much nothing), but I know not all skateboard are the same.
So to create a more "realistics" skateboard class, you should create multiple class, one parent skateboard, and many child depending on the type of skateboard
Each type have more chance to do some tricks, some type can't do some tricks.

You could create a skateboarder class too, depending on his skill, the chance he make the tricks...

#3
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
Should crashing cause you to fall off the skateboard? If so, I would include:

isMoving = false;

isOn = false;

in the else body of each trick method. Or perhaps create a method that performs those two assignments and call it from each trick method to make for fewer lines.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#4
Cruel Hand

Cruel Hand

    Learning Programmer

  • Members
  • PipPipPipPip
  • 109 posts
  • Programming Language:Java
  • Learning:Java, Visual Basic .NET
both of you made valid points/suggestions, thanks :D

#5
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
  • tuna is a weird classname + it doesn't start with a capitalized letter so it is no valid name.
  • You can ask yourself whether it's logical to have getOn, and isOn at a skateboard class.
    I mean, it makes more sence to write if (skateboarder.isOn()) rather than if (skateboard.isOn())


#6
Cruel Hand

Cruel Hand

    Learning Programmer

  • Members
  • PipPipPipPip
  • 109 posts
  • Programming Language:Java
  • Learning:Java, Visual Basic .NET

wim DC said:

  • tuna is a weird classname + it doesn't start with a capitalized letter so it is no valid name.
  • You can ask yourself whether it's logical to have getOn, and isOn at a skateboard class.
    I mean, it makes more sence to write if (skateboarder.isOn()) rather than if (skateboard.isOn())

the tuna class is just a class that is used in a tutorial video and I didn't feel like making a new class so I just used that one. You make a good point about #2 though




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users