Hole without random

import java.util.Scanner;
public class hole2{
String[][] holeStore;
int Ncol=5;
int Nrow=3;
int token;
hole2(){
holeStore = new String[Nrow][Ncol];
for(int i=0; i<Nrow; i++){
for(int j=0; j<Ncol; j++){
holeStore[i][j] = “Free”;
}

}
}

void set_full(int row,int col){
findToken(row,col);
holeStore[row-1][col-1] = Integer.toString(token);
}

void set_Null(int row, int col){
holeStore[row-1][col-1] = “Free”;
}
void findHole(int token){
boolean is_found = false;
for(int i=0; i<Nrow; i++){
for(int j=0; j<Ncol; j++){
if( holeStore[i][j].equals(Integer.toString(token))){
int row = i+1;
int col = j+1;
System.out.println(“Your Row is : “+row);
System.out.println(“Your Colum is “+col);
is_found = true;
     break;
}
}
}
if(is_found == false){
System.out.println(“Sorry Your Token Not Found!\nTry Again.”);
}
}

void findToken(int row, int col){
token = (row-1)*Ncol+col;
System.out.println(“Your Token Is : “+token);
}

void find_free(){
for(int i=0; i<Nrow; i++){
for(int j=0; j<Ncol; j++){
if(holeStore[i][j] == “Free”){
System.out.println(“Row : “+(i+1)+”\tColumn: “+(j+1)+”\t:is Empty”);

}
else{
System.out.println(“Row : “+(i+1)+”\tColumn: “+(j+1)+”\t:is Full”);
}
}
}
}

void current_Status(){
for(int i=0; i<3; i++){
for(int j=0; j<5; j++){
System.out.println((i+1)+” “+(j+1)+” :”+holeStore[i][j]);
}
}
}
void find_first_free(){
boolean empty_found=false;
for(int i=0; i<Nrow; i++){
for(int j=0; j<Ncol; j++){
if(holeStore[i][j] == “Free”){
System.out.println(“You can store at Row : “+(i+1)+”\tColumn: “+(j+1)+”\t:Now!”);
empty_found =true;
break;
}

}

 if(empty_found = false){
System.out.println(“All Holes a full”);
}
}
}

public static void main(String args[]){
int token;
hole2 H = new hole2();
Scanner S = new Scanner(System.in);
int choice;
do{
System.out.println(“What you want to Do:\nEnter the Choice\n1:For Find Token No.\n2:For Find Row & Column\n3:For Find Free Holes”
+”\n4:For Store a thing\n5:For Retrive a thing”+”\n6:For Current Hole Status\n7:Find First Free Hole\n8: For Exit”);
choice = S.nextInt();
if( choice == 2)
{
System.out.println(“Enter your token No:”);
token = S.nextInt();
H.findHole(token);
}
else if( choice ==1)
{
System.out.println(“Enter your Row No:”);
int row = S.nextInt();
System.out.println(“Enter your Column No:”);
int col = S.nextInt();
H.findToken(row,col);
}
else if( choice == 3){
H.find_free();
}
else if( choice ==4){
System.out.print(“Enter Row No:”);
int row = S.nextInt();
System.out.print(“Enter Column No:”);
int col = S.nextInt();
H.set_full(row,col);
System.out.println(“Item has been STORED”);
}
else if( choice ==5){
System.out.print(“Enter Row No:”);
int row = S.nextInt();
System.out.print(“Enter Column No:”);
int col = S.nextInt();
H.set_Null(row,col);
System.out.println(“Thank you Come Again”);
}
else if( choice == 8){
System.exit(0);
}
else if( choice == 6){
H.current_Status();
}
else if(choice == 7){
H.find_first_free();
}
else{
System.out.println(“Invalid Entry”);

}
System.out.println(“***********************”);
}while(choice != 8);
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s