Hello need help figuring out whats wrong here at the the to

Hello need help figuring out whats wrong here ! at the the top and bottom two errors! feedback on the code will also be appreciated thanks.

mport java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class self2 { // error here    - Syntax error, insert \"}\" to complete ClassBody
                                               ///Breakpoint:self2


   public static void main(String[] args)
   {
       //Construction
       double rate = 0;
       double overCharge = 1.10; // Over-baseline charge for KW used
       double excessCharge = 1.25; // Excess charger for KW used
       double tier1 = 350; // Cap of baseline KW used
       double tier2 = 500; // Cap of over-baseline KW used
       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.next();
       System.out.println(\"Meter reading date >\");
       String date = sc.next();
       Scanner sc1 = new Scanner(System.in); // Scanner #1 for KW used input
       String kwusedEntered = null;
       double base = 0;
       boolean isValid = false;
       while (isValid == false) {
           try {
               System.out.print(\"Electricity Used (KW) > \");
               kwusedEntered = sc1.nextLine();
               Integer.parseInt(kwusedEntered);
               isValid = true;

               Scanner sc2 = new Scanner(kwusedEntered); // Scanner #2 for KW used input
               int kwused = sc2.nextInt();

      
       // 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) : \" + kwused);
              
       // Charges
       if (kwused >= 0 && kwused <= 350) {
           base = kwused * rate;
           over = 0;
           excess = 0;
       } else if (kwused > 350 && kwused <= 500) {
           base = tier1 * rate;
           over = (kwused - tier1) * (rate * overCharge);
           excess = 0;
       } else if (kwused > 500)
           base = tier1 * rate;
           over = (tier2 - tier1) * (rate * overCharge);
           excess = (kwused - 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(base);
       System.out.print(over);
       System.out.println(excess);
       System.out.println(total);
      
       System.out.println(\"Thank you for letting us serve you!\ \") ; //error here Syntax error, insert \"}\" to complete Block
       //Syntax error, insert \"Finally\" to complete
       // BlockStatements

  
       } } }  
          

Solution

Hi,

I have modified the code. It is error free now. I have highlighted the coe changes below. Please note that rate field value you given as 0. Becuase of that calculation values coming like 0 always. I have put 10 value to rate. If required, you may chang the rate in below variable.

double rate = 10;

self2.java

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class self2 {

public static void main(String[] args)
{
//Construction
double rate = 10;
double overCharge = 1.10; // Over-baseline charge for KW used
double excessCharge = 1.25; // Excess charger for KW used
double tier1 = 350; // Cap of baseline KW used
double tier2 = 500; // Cap of over-baseline KW used
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 >\");
String date = sc.next();
Scanner sc1 = new Scanner(System.in); // Scanner #1 for KW used input
int kwusedEntered = 0;
double base = 0;
boolean isValid = false;
while (isValid == false) {
try {
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);
  
// 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(base);
System.out.print(over);
System.out.println(excess);
System.out.println(total);
  
System.out.println(\"Thank you for letting us serve you!\ \") ;
sc.nextLine();
} catch(Exception e){
   e.printStackTrace();
}

}
}
  
}   
}

Output:

Southwet Power & Light
Billing Statement
Please enter your name (Last,First) >
Suresh, Murapaka
Meter reading date >
10/01/2016
Electricity Used (KW) > 400
Date printed: 10/11/2016
Name:Suresh, Murapaka
Meter reading date : 10/01/2016
Electricity used (KW) : 400
3500.0
550.00.0
4050.0
Thank you for letting us serve you!

Please enter your name (Last,First) >
Sekhar, Murapaka
Meter reading date >
10/05/2016
Electricity Used (KW) > 500
Date printed: 10/11/2016
Name:Sekhar, Murapaka
Meter reading date : 10/05/2016
Electricity used (KW) : 500
3500.0
1650.00.0
5150.0
Thank you for letting us serve you!

Hello need help figuring out whats wrong here ! at the the top and bottom two errors! feedback on the code will also be appreciated thanks. mport java.text.Date
Hello need help figuring out whats wrong here ! at the the top and bottom two errors! feedback on the code will also be appreciated thanks. mport java.text.Date
Hello need help figuring out whats wrong here ! at the the top and bottom two errors! feedback on the code will also be appreciated thanks. mport java.text.Date
Hello need help figuring out whats wrong here ! at the the top and bottom two errors! feedback on the code will also be appreciated thanks. mport java.text.Date

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site