Hit me with your best shot


Had a wonderful time with Ronashil and Kevin at the Highlands gun range yesterday!
Kev showed us the ropes and he let us try out a few . It was an amazing experience. This is probably why there’s a lot of gun nuts in this country. It’s exhilarating. Squeezing the trigger and the moment you hear that sound and the shock that you feel throughout ones body is indescribable.

You have got to try it out!

PS.
One does’t have to get a license and permit to shoot guns in the range. One just had to be 18 and sign off a waiver and pay 12 bucks,which was the amount they were charging for using the facility. You can even rent their guns , eyes and ear protection and even buy the ammo there.

Remove all Occurrence

This is number 2 from handout #4 : string processing.

/*
* RemoveAllOccurences
*/

import acm.program.*;

public class RemoveAllOccurences extends ConsoleProgram{
	public void run(){	
		while(true){													// infinite loop
			String str1 = readLine("Give me a string(q to exit): ");	// q as a sentinel to break out of the loop
			if(str1.equals("q"))				
				break;
			String str2 = readLine("Give me a character to remove: ");	// give me the char
			
			int charIndex = 0;											// get the first char only
			char ch = str2.charAt(charIndex);							// 
			
			println(removeAllOccurrence(str1,ch));						// call removeAllOccurence
		}
	}
	
	// remove all occurrence of a char in a string
	private String removeAllOccurrence(String str, char ch){
		String result = ""; 								// declare a new String object result
		int firstIndex = 0;									// beginning of the string
		int indexChar =str.indexOf(ch);						// find the index of the first occurrence
		while(indexChar!=-1){ 								//loop through the string str until we find all occurrence
			result+=str.substring(firstIndex,indexChar);	//iterate 
			firstIndex = indexChar+1;						// skip the char
			indexChar = str.indexOf(ch, firstIndex);		// get the next index of the next substring
		}
		return result+str.substring(firstIndex);			//add the end of the result string and return it
	}
}
%d bloggers like this: