In Java, Compute Billing For Home And Corporate Users

public class Bills{

	private static void printBill(final String client, final int connections, final int channels){
		System.out.printf("Client: %s%n", client);
		System.out.printf("No# of connections: %d%n", connections);
		System.out.printf("No# of channels: %d%n", channels);
		float regChg = 5.5f;
		float srvChg = 21.5f;
		float chnChg = 8.5f;
		if(10 < channels){
			chnChg += 0.5f * (channels - 10);
		}
		if("Corporate".equalsIgnoreCase(client)){
			regChg = 15.0f;
			srvChg = 75.0f;
			chnChg = 50.0f;
			if(20 < channels){
				chnChg += 2.0f * (channels - 20);
			}
		}
		if(10 < connections){
			srvChg += 5.0 * (connections-10);
		}
		System.out.printf("Registration charges: $%.2f%n", regChg);
		System.out.printf("Initial service charges: $%.2f%n", srvChg);
		System.out.printf("Premium channels: $%.2f%n", chnChg);
		double total = regChg + srvChg + chnChg;
		System.out.printf("Total charges: $%.2f%n", total);
		System.out.println();
	}

	public static void main(String[]args){
		printBill("Home", 8, 11);
		printBill("Corporate", 11, 22);
	}
}
Download

Comments

Popular posts from this blog

Tecq Mate | Build APK with command line only | Build Android with cmd | No IDE | No Android Studio