Showing posts with label java games. Show all posts
Showing posts with label java games. Show all posts
Tuesday, October 18, 2011 7 comments

CHALLENGE:Java Tut 36-37-Display Reg Time

The following is a challenge for new developers that have completed:
 Java Tutorial - 36-37 Displaying Regular Time by theNewBoston
 To get the most out of these challenges try them a few hours or the day after watching/following along with the actual video.
 

CHALLENGE!!
(Before starting any of the challenges always declare a class and a main method unless told otherwise)
 Difficulty:
 
1.Create a class and name it "Time".Unlike classes we've created in the past you dont need to declare a main method.

2.Create 3 int vars. name them hour, minute, second.

3.Create a method,name it setTime, it should accept 3 parameters(int h, int m , int s)
Inside the setTime method:
  • if h is greater than 0 and less than 24 then set h to hour, else set the hour to 0 by default.This should be accomplished in one line of code( Hint:use the "ternary operator" instead of a if statement)
  • if m is greater than 0 and less than 60 then set m to minute, else set the minute to 0 by default.(Hint: "ternary operator")
  • if s is greater than 0 and less than 60 then set s to second, else set the second to 0 by default.(Hint: "ternary operator")
End "setTime" method 

4.Create another method.Name it toMilitary.
Inside the to Military method:
  • Create a return statement that will format the "hour" , "minute" and "second" vars to display in military format.
    Example of console output:18:30:00
    End "toMilitary" method
5.Create a method,name it toRegTime
Inside the "toRegTime" method:
  • Create a return statement that will format the "hour" , "minute" and "second" vars to display in standard time format. (hint:Ull need to use the Modulus (%) operator
    Example of console output:6:30:00 PM
End "toRegTime" method

End of "Time" class

6.Create another class and name it testTime .Create a main method.

Inside the main method of testTime class:
  • Declare a new Time object and name it tickTock.
  • Print tickTock.toMilitary
  • Print tickTock.toRegTime
  • Call the setTime method with the parameters (13,27,6)
  • Print tickTock.toMilitary
  • Print tickTock.toRegTime
End of "testTime" class
COMPILE & PRAY TO DUKE!!!
View the video tutorial: http://bit.ly/qkxfja 

Wednesday, October 12, 2011 0 comments

CHALLENGE:Java Tut 35-Var Length Arguments

The following is a challenge for new developers that have completed:
 Java Tutorial - 35 Variable Length Arguments by theNewBoston
 To get the most out of these challenges try them a few hours or the day after watching/following along with the actual video.
 


B.A.M.F Challenge:
B.A.M.F Challenges & why you want to always at leas try them explained Here:http://bit.ly/ogivqe
Difficulty: 1/3
Create a console program with a method that finds the average of a unknown amount of numbers(aka accepts a variable length argument in its parameters)Then test it in you're main method.

CHALLENGE!!
(Before starting any of the challenges always declare a class and a main method unless told otherwise)
 Difficulty:
 
1.Create a method that will return a int and name it "average".It should accept a variable length argument, name the variable length argument "numbers"

Inside the "average" method:

2.Declare a int variable, name it total and set it to 0.

3.Create a enhanced for loop that loops through the "numbers" parameter being passed in.

Inside the enhanced for loop:
4.set total+=x;

5.return total divided by the amount of numbers you passed in(hint: numbers.length)

Back in the main method:


6.Create a print line statement that calls the "average" method and place 8 values in its parameters.


COMPILE & PRAY TO DUKE!!!


View the video tutorial: http://bit.ly/qkxfja 

 
;