SQL

Saturday, 15 August 2015

Case Study: Student Grading System



Welcome to grade book for CS101 Introduction to Java Programming

The grades are :

Student  1:  87
Student  2:  68
Student  3:  94
Student  4: 100
Student  5:  83
Student  6:  78
Student  7:  85
Student  8:  91
Student  9:  76
Student 10:  87
Class average is 84.90
Class Minimum is 68Class Maximum is 100
Grade Distribution

00-09 :
10-19 :
20-29 :
30-39 :
40-49 :
50-59 :
60-69 :*
70-79 :**
80-89 :****
90-99 :**
  100 : *

Friday, 14 August 2015

Case Study: Card Shuffling and Dealing Simulation


The elements of an array can be either primitive types or reference types. This example uses random-number generation and an array of reference type elements, namely objects representing playing cards, to develop a class that simulates card shuffling and dealing. This class can then be used to implement applications that play specific card games. 

I first develop class Card , which represents a playing card that has a face
(e.g., "Ace", "Deuce", "Three", …, "Jack", "Queen", "King") and a suit (e.g., "Hearts", "Diamonds", "Clubs", "Spades"). Next, I develop the DeckOfCards class, which creates a deck of 52 playing cards in which each element is a Card object. I then build a test application that demonstrates class DeckOfCards’s card shuffling and dealing capabilities.





Output:

Jack of Clubs      Nine of Hearts     Jack of Hearts     Nine of Diamond  
Six of Clubs       Seven of Diamond   Queen of Diamond   Eight of Spades  
Queen of Clubs     Ace of Hearts      Five of Clubs      King of Hearts    
Eight of Clubs     Eight of Diamond   Ten of Diamond     King of Clubs    
Jack of Diamond    Queen of Spades    Four of Clubs      Five of Hearts    
Jack of Spades     Seven of Hearts    Three of Clubs     Four of Spades    
Ace of Clubs       Five of Spades     Ten of Clubs       Ace of Spades    
King of Spades     Six of Diamond     King of Diamond    Nine of Clubs    
Deuce of Spades    Six of Hearts      Six of Spades      Ten of Spades    
Deuce of Diamond   Queen of Hearts    Three of Diamond   Deuce of Clubs    
Three of Spades    Seven of Spades    Four of Diamond    Three of Hearts  
Seven of Clubs     Ten of Hearts      Five of Diamond    Eight of Hearts  
Ace of Diamond     Four of Hearts     Deuce of Hearts    Nine of Spades    

toString() in Java

Method toString()

All object has a toString method that returns the string representation of that object. When an object is concatenated with a string, the object's toString is implicitly called to obtain the string representation of that object. toString also can be called explicitly.

Example:


Output:

X=10 Y=10
X=10 Y=10 testing

Wednesday, 12 August 2015

Game of Chance in Java

Case Study: A Game of Chance

A popular game of chance is a dice game known as craps, which is played in casinos andback alleys throughout the world. The rules of the game are straightforward:
You roll two dice. Each die has six faces, which contain one, two, three, four, five and six spots, respectively. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first throw, you win. If the sum is 2, 3 or 12 on the first throw (called “craps”), you lose (i.e., the “house” wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, that sum becomes your “point.” To win, you must continue rolling the dice until you “make your point” (i.e., roll that same point value). You lose by rolling a 7 before making your point.


Tic Tac Toe in Java