Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

sir please tell how to fix this type of error (regarding buffered reader)

–1 vote
asked Nov 3, 2019 by parth
import java.io.*;
 class prg {
     public void main () throws IOException
     {
      BufferedReader br =new BufferedReader (new InputStreamReader(System.in));
        string name ;
        int sn;
        double amt ,disc,net;
        for (sn=1;sn<=15;sn++)
        { System.out.println("enter name ");
            name= br.readLine();
            System.out.println("enter ticket amount ");
            amt=Double.parseDouble(br.readLine());
           if  (amt>70000)
           disc=0.18*amt;
           
           else if (amt >55000)
           disc=0.16*amt;
           else if(amt>35000)
           disc=0.12*amt;
           else if (amt>25000)
           disc=0.10*amt;
           else
           disc =0.02*amt;
           net=amt-disc;
           System.out.println(sn+"\t"+name+"\t"+amt+"\t"+disc + "\t"+net);
        }
    }
}

1 Answer

0 votes
answered Nov 4, 2019 by anonymous

1. Missing headers  for (BufferedReader and InputStreamReader )

2. Missing Exception Handler for BufferedReader

3. lowercase "string" used in place of "String" class

import java.io.BufferedReader;

import java.io.InputStreamReader;

public class Main

{

  public static void main (String[]args)

  {

    try

    {

      BufferedReader br =

new BufferedReader (new InputStreamReader (System.in));

      String name;

      int sn;

      double amt, disc, net;

      for (sn = 1; sn <= 15; sn++)

{

  System.out.println ("enter name ");

  name = br.readLine ();

  System.out.println ("enter ticket amount ");

  amt = Double.parseDouble (br.readLine ());

  if (amt > 70000)

    disc = 0.18 * amt;

  else if (amt > 55000)

    disc = 0.16 * amt;

  else if (amt > 35000)

    disc = 0.12 * amt;

  else if (amt > 25000)

    disc = 0.10 * amt;

  else

    disc = 0.02 * amt;

  net = amt - disc;

  System.out.println (sn + "\t" + name + "\t" + amt + "\t" + disc +

      "\t" + net);

}

    }

    catch (Exception ex)

    {

      ex.printStackTrace ();

    }

  }

}

commented Nov 4, 2019 by DSG
import java.io.*;
public  class prg {
     public static void main (String args[]) throws IOException
     {
      BufferedReader br =new BufferedReader (new InputStreamReader(System.in));
      String name ;
        int sn;
        double amt ,disc,net;
        for (sn=1;sn<=15;sn++)
        { System.out.println("enter name ");
            name= br.readLine();
            System.out.println("enter ticket amount ");
            amt=Double.parseDouble(br.readLine());
           if  (amt>70000)
           disc=0.18*amt;
           
           else if (amt >55000)
           disc=0.16*amt;
           else if(amt>35000)
           disc=0.12*amt;
           else if (amt>25000)
           disc=0.10*amt;
           else
           disc =0.02*amt;
           net=amt-disc;
           System.out.println(sn+"\t"+name+"\t"+amt+"\t"+disc + "\t"+net);
        }
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...