Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- public class FinalProject {
- static ArrayList<String> name = new ArrayList<String> ();
- static ArrayList<String> address = new ArrayList<String> ();
- static ArrayList<Double> prevMreading = new ArrayList<Double> ();
- static ArrayList<Double> currMreading = new ArrayList<Double> ();
- static ArrayList<Double> Dues = new ArrayList<Double> ();
- static ArrayList<Double> consumption = new ArrayList<Double> ();
- static ArrayList<String> discount = new ArrayList<String> ();
- static Scanner scr = new Scanner(System.in);
- public static void main(String[] args) {
- int mainMenu = -1;
- while (mainMenu != 0) {
- menu();
- mainMenu = scr.nextInt();
- scr.nextLine();
- switch (mainMenu) {
- case 0:
- exit();
- break;
- case 1:
- add(6);
- break;
- case 2:
- update();
- break;
- case 3:
- display();
- break;
- case 4:
- search();
- break;
- default:
- System.out.println("Out of range");
- break;
- }
- }
- }
- static void menu() {
- 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(int quarter) {
- String name, address;
- double prev, curr, due = 0.0, sub = 0.0;
- int rate;
- System.out.println("------Create a new user account!------");
- System.out.println("Name: ");
- name = scr.nextLine();
- FinalProject.name.add(name);
- System.out.println("Address: ");
- address = scr.nextLine();
- FinalProject.address.add(address);
- System.out.println("Previous reading: ");
- prev = scr.nextDouble();
- prevMreading.add(prev);
- System.out.println("Current reading: ");
- curr = scr.nextDouble();
- currMreading.add(curr);
- System.out.println("[1] Residential");
- System.out.println("[2] Business");
- rate = scr.nextInt();
- double consumed = curr - prev;
- consumption.add(consumed);
- 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;
- }
- }
- int yearser;
- System.out.println("how many years in using the service?");
- yearser = scr.nextInt();
- if (yearser >= 15 ) {
- due = sub - (sub * (15/100));
- discount.add("15% promo discount applied!");
- } else {
- due = sub;
- discount.add("No promo discount appllied!");
- }
- Dues.add(due);
- }
- static void update() {
- String name, newName, newAddress;
- System.out.println("------Update a current account------!");
- System.out.println("Name: ");
- name = scr.nextLine();
- int position = 0;
- boolean matched = false;
- for (String profile : FinalProject.name) {
- if (profile.contains(name)) {
- matched = true;
- position = FinalProject.name.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- }
- if (matched == true) {
- int modify;
- System.out.println("[1] Update name");
- System.out.println("[2] Update address");
- modify = scr.nextInt();
- scr.nextLine();
- switch (modify) {
- case 1:
- System.out.println("New name: ");
- newName = scr.nextLine();
- FinalProject.name.set(position, newName);
- break;
- case 2:
- System.out.println("New address: ");
- newAddress = scr.nextLine();
- address.set(position, newAddress);
- break;
- default:
- System.out.println("Unknown command!");
- break;
- }
- } else {
- System.out.println("No data found");
- }
- }
- static void display() {
- System.out.println("------Show accounts for all users!------");
- for (int i = 0; i < name.size(); i++) {
- System.out.println("Name: " + name.get(i));
- System.out.println("Address: " + address.get(i));
- System.out.println("Previous reading: " + prevMreading.get(i));
- System.out.println("Current reading: " + currMreading.get(i));
- System.out.println("Current consumption: " + consumption.get(i));
- System.out.println("Total payment due: " + Dues.get(i));
- }
- }
- static void search() {
- int position = 0, searchBy;
- String name, address;
- boolean matched = false;
- System.out.println("------Try looking for an account here!------");
- System.out.println("[1] By name");
- System.out.println("[2] By address");
- searchBy = scr.nextInt();
- scr.nextLine();
- switch (searchBy) {
- case 1:
- System.out.print("Name: ");
- name = scr.nextLine();
- for (String profile : FinalProject.name) {
- if (profile.contains(name)) {
- matched = true;
- position = FinalProject.name.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- } break;
- case 2:
- System.out.print("Address: ");
- address = scr.nextLine();
- for (String profile : FinalProject.address) {
- if (profile.contains(address)) {
- matched = true;
- position = FinalProject.address.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- } break;
- default:
- System.out.println("Unknown command");
- break;
- }
- if (matched == true) {
- System.out.println("Name: " + FinalProject.name.get(position) +
- "\nAddress: " + FinalProject.address.get(
- position) +
- "\nPrevious reading: " + prevMreading.get(position) +
- "\nCurrent reading: " + currMreading.get(position) +
- "\nCurrent consumption: " + consumption.get(position) +
- "\nTotal payment due: " + Dues.get(position) +
- "\nPromo: " + discount.get(position) +
- "\n"
- );
- }
- }
- static int exit() {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment