0% found this document useful (0 votes)
37 views

Presentación 1 - Java 2

This document provides an overview of topics in Java basics including formatted output, working with strings, casting, and generating random numbers. It outlines printing different data types, declaring and manipulating strings, casting between primitive types, and using the Random class. It concludes with an example program for a Hangman game that chooses a random secret word, tracks letter guesses, and displays the current game state.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Presentación 1 - Java 2

This document provides an overview of topics in Java basics including formatted output, working with strings, casting, and generating random numbers. It outlines printing different data types, declaring and manipulating strings, casting between primitive types, and using the Random class. It concludes with an example program for a Hangman game that chooses a random secret word, tracks letter guesses, and displays the current game state.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Java Basics II

Christian Rodrguez Bustos


Object Oriented Programming

Java Basics

Agenda
Formatted
output

Working with
Strings

Casting

Generating
Random
numbers
Java Basics

Formatted Output
[Deitel] Chapter 28

Printing Integers & Floating-Point Numbers


Printing Strings and characters
Printing Dates and times

Java Basics

Printing Integers Numbers

Printing Integers Numbers

Java Basics

Printing Floating-Point Numbers

Java Basics

Printing Floating-Point Numbers

Java Basics

Printing Strings and characters

Java Basics

Printing Strings and characters

Java Basics

Printing Dates and times

Java Basics

Printing Dates and times

Java Basics

Working with Strings


[Deitel] Chapter 29

Strings Declarations
String Miscellaneous

Strings Declarations

String Miscellaneous

Java Basics

String Miscellaneous

Java Basics

Casting
Primitive Types Casting

Primitive Types Casting

Assignation variable

Value
to
assign

int

long

float

double

char

byte

short

boolean

int

long

float

double

char

byte

short

boolean

C = Explicit Cast Required

A = Automatic Cast

Casting example

Java Basics

ASCII table

Java Basics

Working with Random numbers

Generating random numbers

Remember to import the


Random Class

Generating random numbers

Generating random numbers

Java Basics

HangMan

Write the program HangMan


Program must choose randomly the secret word from a
predefined list. (Given by me )
Program must show after each player turn the current
game state:
Which letters has been discovered. For example:

_b_e_t_

(Objects)

How many errors has been committed until complete this figure
q(x_x)p

Which letters has been used

Java Basics

Game Output example


System (Secret word = object)

Player

______
User try the letter a
______

a
User try the letter j

__j___

aj
User try the letter w

__j___

q(

ajw
User try the letter n

__j___

q(X

ajnw
User try the letter b

_bj___

q(X

abjnw

Java Basics

Game Output example


System (Secret word = object)
objec_

q(X_X)

Player

abcde...
User try the letter t

object

q(X_X)

abcde...

You Win !!!

System (Secret word = object)


objec_

q(X_X)

Player

abcde...
User try the letter p

object

q(X_X)P

abcde...

You Lose !!! The secret word is: object

Java Basics

References

[Barker] J. Barker, Beginning Java Objects: From Concepts To Code,


Second Edition, Apress, 2005.
[Deitel] H.M. Deitel and P.J. Deitel, Java How to Program: Early Objects
Version, Prentice Hall, 2009.

Java Basics

You might also like