Skip to main content

Bowling With Friends In Fremont

Last week I went to bowling with my friends in Fremont and we enjoyed it a lot. I paid on behalf of them for the game so that everyone else pay me back later. Despite their repeated query to know how much they should pay me, I was too busy the whole last week to calculate that. Right now, having a little relax time, so I downloaded JDK 6 in my new laptop from office and wrote the small java program to calculate it. Compile and run the program to know how much I owe to each of them.

/**
* To compile: javac -d . BowlingCost.java
* To run: java BowlingCost
*/

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
public class BowlingCost {
public static final double shoeRent = 4.0;
public static final double perGame = 4.25;
private static int male = 5;
private static int female = 4;
private static Map payersMaritalStatus = new HashMap();
public BowlingCost() {
payersMaritalStatus.put("Shahriar", Boolean.TRUE);
payersMaritalStatus.put("Ezaz", Boolean.TRUE);
payersMaritalStatus.put("Hasinur", Boolean.TRUE);
payersMaritalStatus.put("Nitol", Boolean.FALSE);
payersMaritalStatus.put("Ashik", Boolean.TRUE);
}
public static void main(String []args) {
BowlingCost cost = new BowlingCost();
System.out.println("Total Cost of Bowling = " + calculateTotal() + " dollars.\n");
displayPaymentAmounts();
System.out.println("\nThank you! It was a pleasure playing bowling with you guys!!");
}
private static double calculateTotal() {
return perGame * (male * 3 + female * 1) + shoeRent * (male + female);
}
private static void displayPaymentAmounts() {
Iterator it = payersMaritalStatus.keySet().iterator();
String payerName = null;
boolean isMarried = false;
while(it.hasNext()) {
payerName = (String) it.next();
isMarried = ((Boolean) payersMaritalStatus.get(payerName)).booleanValue();
if(isMarried) {
System.out.println(payerName + " should pay " + (perGame * (3 + 1) + shoeRent * (1 + 1)) + " dollars.");
} else {
System.out.println(payerName + " should pay " + (perGame * 3 + shoeRent * 1) + " dollars.");
}
}
}
}

If you don't want to run the program in command line or opening your favorite IDE, then you can use the following online java compiler to copy paste the code there (select Java SE 1.4 class from the drop down box at the bottom).

http://www.zamples.com/JspExplorer/index.jsp?format=jdk16cl

Here is the output if you run the program:

Total Cost of Bowling = 116.75 dollars.

Ezaz should pay 25.0 dollars.
Ashik should pay 25.0 dollars.
Hasinur should pay 25.0 dollars.
Shahriar should pay 25.0 dollars.
Nitol should pay 16.75 dollars.

Thank you! It was a pleasure playing bowling with you guys!!

Comments

Popular posts from this blog

Moved To New House & Tuhin Bhai's Quick Visit

We moved to a new rental house near BART end of last month. We have stayed in LakeView Apartments for three and half years before moving here. I was too busy with my office works the last month and hence Shusmita did most of the packings. We got the new house key 1 week earlier than our move in date of first November. So we actually moved 24th October Saturday and took rest of the one week to slowly finish the moves. We rented DesiMovers who moved all out packed cartoon (30+) and many unpacked staffs. They disassembled the bed and assembled back again. Although a bit costly, they were quick and did a good job of transferring all the staffs and assembling those back again. All our friends in Fremont liked the house as we did. I wish I would not be a tenant but the owner of the house! However, buying house is very expensive in California and I can't simply afford it maintaining my current lifestyle, I let myself forget about it. Tuhin Bhai (Ripa's hubby) gave a surprise visit...

Bought New Car: Honda Accord 2009 LX-P Maroon Color

After a month of my Civic being completely destroyed in a car accident, I bought my new car yesterday. It's Honda Accord 2009 LX-P Maroon Color that I bought from Autowest Honda of Fremont . I have shopped around for car in Toyota and Honda. While Toyota Camry 2010 is also a very good car, somehow we ended up liking Accord. Whlile in Accord you feel the road and the power behind the car more, for Camry it's the smoothness of driving experience. Shusmita didn't want to even go for a test drive of Hyundai Sonata although that is also a comparable car at a cheaper price. I guess we are so used to our Honda Civic that only another Honda car would have been able to psychologically match our unknown requirements. I gave a four thousand dollars down payment and the rest my dealer financed me from American Honda Finance. While buying the car, I also bought the 6 years service, mechanical breakdown warranty, low jack safety and some service contracts. I came to know at that time t...

Sachin Wins 1st Test Against Chennai Chasing 387 with unbeaten century

I followed most of the first test and almost all of the fifth day's magical chase of Tendulkar winning the test against England in Chennai with a fine 103 not out. It was a dream come true for me like many others to see Sachin in this perfect role . Read the details here - http://content-usa.cricinfo.com/indveng/content/current/story/382035.html There are so many good batting points he wrote besides his yesterday and one of those are his 3rd fourth innings century where he is ahead of Lara, equal to Bradman but behind Pointing yet. Last year, Tendulkar made a fourth innings half-century (56*) to defeat Pakistan as I observed that with intense as well like this time as I knew Tendulkar has a poor fourth innings record compared to Ponting or Gavaskar (and almost same as Lara). Not to the same scale worthy of mentioning that amongst all his fourth innings Tendulkar had 36* not out chasing 184 against Zimbabwe in 2001 and 32 * not out chasing 123 against South Africa in 2004. H...