Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WaterBilling {
- static String name,address;
- static double prevReading,currReading,sub = 0.0,due = 0.0,consumed;
- static int rate,yearser;
- static Scanner scr = new Scanner(System.in);
- public static void main (String[]args){
- int mainMenu = -1;
- while (mainMenu != 0) { //while loop for looping the menu until the user press exit
- menu(); //calling the menu user defined method
- mainMenu = scr.nextInt(); //getting user choice
- scr.nextLine();
- switch (mainMenu) {
- case 0:
- exit();
- break;
- //calling the userdefined methods
- case 1:
- add();
- break;
- //calling the userdefined methods
- case 2:
- //calling the userdefined methods
- case 3:
- display();
- break;//calling the userdefined methods
- case 4:
- //calling the userdefined methods
- default: System.out.println("Out of range");
- }
- }
- }
- static void menu() { //the menu output
- System.out.println("-------[Water Billing System]-------");
- System.out.println("[1] Create a new user account.");
- System.out.println("[2] Update a current account");
- System.out.println("[3] Show accounts for all users.");
- System.out.println("[4] Try looking for an account here.");
- System.out.println("[0] Exit");
- }
- static void add(){
- System.out.println("Name: ");
- name = scr.nextLine();
- System.out.println("Address: ");
- address = scr.nextLine();
- System.out.println("Previous Meter Reading: ");
- prevReading = scr.nextDouble();
- System.out.println("Current Meter Reading: ");
- currReading = scr.nextDouble();
- consumed = currReading - prevReading;
- System.out.println("[1] Residential");
- System.out.println("[2] Business");
- rate = scr.nextInt();
- if (rate == 1) {
- if (consumed > 10) {
- sub = 200 + ((consumed - 10) * 30);
- }
- if (consumed <= 10) {
- sub = 200;
- }
- } else if (rate == 2) {
- if (consumed > 20) {
- sub = 500 + ((consumed - 20) * 50);
- }
- if (consumed <= 20) {
- sub = 500;
- }
- System.out.println("how many years in using the service?");
- yearser = scr.nextInt();
- if (yearser >= 15 ) {
- due = sub - (sub * (15/100));
- System.out.println("15% promo discount applied!");
- } else {
- due = sub;
- System.out.println("No promo discount appllied!");
- }
- }
- }
- static void display(){
- System.out.println("Name: "+name);
- System.out.println("Address: "+address);
- System.out.println("Previous Meter Reading: "+prevReading);
- System.out.println("Current Meter Reading: "+currReading);
- System.out.println("Total Payment Due: "+due);
- }
- static int exit() {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment