import javatextSimpleDateFormat import javautilDate import j

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Scanner;

public class project1l {

   public static void main(String[] args) {

       // Construction

       double rate = 0;

       double overCharge = 1.10;

       double excessCharge = 1.25;

       double tier1 = 350;

       double tier2 = 500;

       double over = 0;

       double excess = 0;

       double total = 0;

       // Welcome

       System.out.println(\"Southwet Power & Light \ Billing Statement\");

       Scanner sc = new Scanner(System.in);

       String choice = \"y\";

       while (choice.equalsIgnoreCase(\"y\")) {

           // get the input from the user

           System.out.println(\"Please enter your name (Last,First) > \");

           String name = sc.nextLine();

           System.out.println(\"Meter reading date(MM/dd/yyyy) >\");

           String date = sc.nextLine();

           Scanner sc1 = new Scanner(System.in); // Scanner #1 for KW used

           // input

           double kwusedEntered = 0;

           double base = 0;

           boolean isValid = false;

           while (isValid == false) {

               System.out.print(\"Electricity Used (KW) > \");

               kwusedEntered = sc1.nextInt();

               isValid = true;

               // Get current date and time

               Date now = new Date();

               SimpleDateFormat sdf = new SimpleDateFormat(\"MM/dd/yyyy\");

               System.out.println(\"Date printed: \" + sdf.format(now));

               System.out.println(\"Name:\" + name);

               System.out.println(\"Meter reading date : \" + date);

               System.out.println(\"Electricity used (KW) : \" + kwusedEntered);

               String monthStr = date.split(\"/\")[0];

               int month = Integer.parseInt(monthStr.trim());

               if (month == 12 || month == 1 || month == 2)

                   rate = 0.10;

               else if (month >= 3 && month < 6)

                   rate = 0.12;

               else

                   rate = 0.15;

               // Validate Date Entered

               String billingDate = null;

               boolean valid = false;

               while (!valid) {

                   try {

                       Scanner scandate = new Scanner(System.in); // Scanner #1

                       // for

                       // scanning

                       // date

                       System.out.print(\"Meter reading date(MM/dd/yyyy) > \");

                       billingDate = scandate.nextLine();

                       // Charges

                       if (kwusedEntered >= 0 && kwusedEntered <= 350) {

                           base = kwusedEntered * rate;

                           over = 0;

                           excess = 0;

                       } else if (kwusedEntered > 350 && kwusedEntered <= 500) {

                           base = tier1 * rate;

                           over = (kwusedEntered - tier1) * (rate * overCharge);

                           excess = 0;

                       } else if (kwusedEntered > 500) {

                           base = tier1 * rate;

                           over = (tier2 - tier1) * (rate * overCharge);

                           excess = (kwusedEntered - tier2) * (rate * excessCharge);

                       }

                       base = Math.round(base * 100) / 100;

                       over = Math.round(over * 100) / 100;

                       excess = Math.round(excess * 100) / 100;

                       total = base + over + excess;

                       System.out.println(\"Baseline charge \" + base);

                       System.out.println(\"Over-baseline charge \" + over);

                       System.out.println(\"Excess charge\" + excess);

                       System.out.println(\"total amount due \" + total);

                       System.out.println(\"Calculate another bill (y/n)\");

                       choice = sc.next();

                       System.out.println(\"\ Thank you for letting us serve you!\");

                   } catch (Exception e) {

                       e.printStackTrace();

                   }

               }

           }

       }

   }

}

Solution


/**
* The modified java program project1l that prints the output
* of the program as shown in the given output format in the post.
* */
//project1l.java
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class project1l {
   public static void main(String[] args) {

       // Construction
       double rate = 0;
       double overCharge = 1.10;
       double excessCharge = 1.25;
       double tier1 = 350;
       double tier2 = 500;
       double over = 0;
       double excess = 0;
       double total = 0;


       // Welcome message
       System.out.println(\"\\t\\tSouthwet Power & Light \ \\t\\t Billing Statement\");
       Scanner sc = new Scanner(System.in);
       String choice = \"y\";

       while (choice.equalsIgnoreCase(\"y\")) {

           // get the input from the user
           System.out.print(\"Please enter your name (Last,First) > \");
           String name = sc.nextLine();

           System.out.print(\"Meter reading date(MM/dd/yyyy) >\");
           String date = sc.nextLine();
          
           Scanner sc1 = new Scanner(System.in); // Scanner #1 for KW used

           // input
           double kwusedEntered = 0;
           double base = 0;
           boolean isValid = false;
           while (isValid == false) {
               System.out.print(\"Electricity Used (KW) > \");
               //read as string and convert to integer
               kwusedEntered = Integer.parseInt(sc1.nextLine());
               isValid = true;
               // Get current date and time
               Date now = new Date();

               SimpleDateFormat sdf = new SimpleDateFormat(\"MM/dd/yyyy\");

               System.out.println(\"\ \ Date printed: \" + sdf.format(now));
               System.out.println(\"Name:\" + name);
               System.out.println(\"Meter reading date : \" + date);
               System.out.println(\"Electricity used (KW) : \" + kwusedEntered);
               String monthStr = date.split(\"/\")[0];
               int month = Integer.parseInt(monthStr.trim());
               if (month == 12 || month == 1 || month == 2)
                   rate = 0.10;
               else if (month >= 3 && month < 6)
                   rate = 0.12;
               else
                   rate = 0.15;
              
               // Calculate Charges
               if (kwusedEntered >= 0 && kwusedEntered <= 350) {

                   base = kwusedEntered * rate;

                   over = 0;

                   excess = 0;

               } else if (kwusedEntered > 350 && kwusedEntered <= 500) {

                   base = tier1 * rate;

                   over = (kwusedEntered - tier1) * (rate * overCharge);

                   excess = 0;

               } else if (kwusedEntered > 500) {
                   base = tier1 * rate;                  
                   over = (tier2 - tier1) * (rate * overCharge);

                   excess = (kwusedEntered - tier2) * (rate * excessCharge);
               }
              
               total = base + over + excess;

               //Note : using format specifier %s for string
               //%f for double
               //%where number is width specifier
               //% - sign for left alignment in console
              
               System.out.printf(\"\ \ %-30s$%5.2f\",\"Baseline charge\",base);
               System.out.printf(\"%-30s$%5.2f\",\"\ Over-baseline charge\",over);
               System.out.printf(\"%-30s$%5.2f\" ,\"\ Excess charge\",excess);

               System.out.printf(\"\ \ %-30s$%5.2f\",\"Total amount due:\",total);

               System.out.println(\"\ \ Calculate another bill (y/n)\");

               choice = sc.nextLine();
               System.out.println(\"\ \\t\\tThank you for letting us serve you!\");

           }

       }

   }
}

------------------------------------------------------------------------------------------------------------

Sample output:

        Southwet Power & Light
       Billing Statement
Please enter your name (Last,First) > Curl.S.
Meter reading date(MM/dd/yyyy) >2/15/2016
Electricity Used (KW) > 550


Date printed: 10/14/2016
Name:Curl.S.
Meter reading date : 2/15/2016
Electricity used (KW) : 550.0


Baseline charge               $35.00
Over-baseline charge         $16.50
Excess charge                $ 6.25

Total amount due:             $57.75

Calculate another bill (y/n)
y

       Thank you for letting us serve you!
Please enter your name (Last,First) > Krish
Meter reading date(MM/dd/yyyy) >2/16/2016
Electricity Used (KW) > 600


Date printed: 10/14/2016
Name:Krish
Meter reading date : 2/16/2016
Electricity used (KW) : 600.0


Baseline charge               $35.00
Over-baseline charge         $16.50
Excess charge                $12.50

Total amount due:             $64.00

Calculate another bill (y/n)
n

       Thank you for letting us serve you!

import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class project1l { public static void main(String[] args) { // Constru
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class project1l { public static void main(String[] args) { // Constru
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class project1l { public static void main(String[] args) { // Constru
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class project1l { public static void main(String[] args) { // Constru
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class project1l { public static void main(String[] args) { // Constru
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class project1l { public static void main(String[] args) { // Constru

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site