Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.Random;
- public class FinalProject {
- static ArrayList<String> names = new ArrayList<String> ();
- static ArrayList<String> addresses = new ArrayList<String> ();
- static ArrayList<Double> prevReadings = new ArrayList<Double> ();
- static ArrayList<Double> currReadings = new ArrayList<Double> ();
- static ArrayList<Double> paymentDues = new ArrayList<Double> ();
- static ArrayList<Integer> since = new ArrayList<Integer> ();
- static ArrayList<Double> consumptions = new ArrayList<Double> ();
- static ArrayList<String> discounts = new ArrayList<String> ();
- static Scanner input = new Scanner(System.in);
- public static void main(String[] args) {
- Random months = new Random();
- int currentMonth = months.nextInt((12 - 1) + 1)+1;
- int mainMenu = -1;
- final int month = currentMonth;
- System.out.println("Current month: " + currentMonth);
- while (mainMenu != 0) {
- menu();
- mainMenu = input.nextInt();
- input.nextLine();
- switch (mainMenu) {
- case 0:
- exit();
- break;
- case 1:
- add(month);
- break;
- case 2:
- update();
- break;
- case 3:
- display();
- break;
- case 4:
- search();
- break;
- case 8:
- System.out.println("Current month: " + month);
- break;
- default:
- System.out.println("Out of range");
- main(args);
- break;
- }
- }
- }
- static void menu() {
- System.out.println("Water Billing System");
- System.out.println("[1] Add new account");
- System.out.println("[2] Update existing account");
- System.out.println("[3] Display all accounts");
- System.out.println("[4] Search for account");
- System.out.println("[0] Exit");
- System.out.print(">>> ");
- }
- static void add(int quarter) {
- Random rng = new Random();
- String name, address;
- double prev, curr, due = 0.0, sub = 0.0;
- int rate;
- System.out.println("Add new user!");
- System.out.println("Name: ");
- name = input.nextLine();
- names.add(name);
- System.out.println("Address: ");
- address = input.nextLine();
- addresses.add(address);
- System.out.println("Previous reading: ");
- prev = input.nextDouble();
- prevReadings.add(prev);
- System.out.println("Current reading: ");
- curr = input.nextDouble();
- currReadings.add(curr);
- System.out.println("[1] Residential");
- System.out.println("[2] Business");
- System.out.print(">>> ");
- rate = input.nextInt();
- double consumed = curr - prev;
- consumptions.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 yearInService = rng.nextInt(26);
- since.add(yearInService);
- if (yearInService >= 15 && (quarter == 1 || quarter == 4 || quarter == 7 || quarter == 10)) {
- due = sub - (sub * (15/100));
- discounts.add("15% promo discount applied!");
- } else {
- due = sub;
- discounts.add("No promo discount appllied!");
- }
- paymentDues.add(due);
- }
- static void update() {
- String name, newName, newAddress;
- System.out.println("Update account!");
- System.out.println("Name: ");
- name = input.nextLine();
- int position = 0;
- boolean matched = false;
- for (String profile : names) {
- if (profile.contains(name)) {
- matched = true;
- position = names.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- }
- if (matched == true) {
- int modify;
- System.out.println("[1] Update name");
- System.out.println("[2] Update address");
- modify = input.nextInt();
- input.nextLine();
- switch (modify) {
- case 1:
- System.out.println("New name: ");
- newName = input.nextLine();
- names.set(position, newName);
- break;
- case 2:
- System.out.println("New address: ");
- newAddress = input.nextLine();
- addresses.set(position, newAddress);
- break;
- default:
- System.out.println("Unknown command!");
- break;
- }
- } else {
- System.out.println("No data found");
- }
- }
- static void display() {
- System.out.println("All accounts!");
- for (int i = 0; i < names.size(); i++) {
- System.out.println("Name: " + names.get(i));
- System.out.println("Address: " + addresses.get(i));
- System.out.println("Previous reading: " + prevReadings.get(i));
- System.out.println("Current reading: " + currReadings.get(i));
- System.out.println("Current consumption: " + consumptions.get(i));
- System.out.println("Total payment due: " + paymentDues.get(i));
- }
- }
- static void search() {
- int position = 0, searchBy;
- String name, address;
- boolean matched = false;
- System.out.println("Search an account!");
- System.out.println("[1] By name");
- System.out.println("[2] By address");
- System.out.print(">>> ");
- searchBy = input.nextInt();
- input.nextLine();
- if (searchBy == 1) {
- System.out.print("Name: ");
- name = input.nextLine();
- for (String profile : names) {
- if (profile.contains(name)) {
- matched = true;
- position = names.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- }
- } else if (searchBy == 2) {
- System.out.print("Address: ");
- address = input.nextLine();
- for (String profile : addresses) {
- if (profile.contains(address)) {
- matched = true;
- position = addresses.indexOf(profile);
- break;
- } else {
- matched = false;
- }
- }
- } else {
- System.out.println("Unknown command");
- }
- if (matched == true) {
- System.out.println(
- "Name: " + names.get(position) +
- "\nAddress: " + addresses.get(
- position) +
- "\nCustomer since: " + (2022 -
- since.get(position)) +
- "\nPrevious reading: " + prevReadings.get(position) +
- "\nCurrent reading: " + currReadings.get(position) +
- "\nCurrent consumption: " + consumptions.get(position) +
- "\nTotal payment due: " + paymentDues.get(position) +
- "\nPromo: " + discounts.get(position) +
- "\n"
- );
- }
- }
- static int exit() {
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment