Computer Science, asked by thefiregirl25, 5 months ago

please solve this program. In java. ​

Attachments:

Answers

Answered by anindyaadhikari13
2

Program:-

This is the required program.

import java.util.*;

class ElecBill

{

String n;

int units;

double bill;

void accept()

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the name: ");

n=sc.nextLine();

System.out.print("Enter Number of Units consumed: ");

units=sc.nextInt();

}

void calc()

{

if(units<=100)

bill=2.0*units;

else if(units <=300)

bill=3.0*units;

else

bill=5.0*units;

}

void print()

{

System.out.println("Name: "+n);

System.out.println("Units consumed: "+units);

System.out.println("Bill Amount: "+bill);

}

// main method.

public static void main(String args[])

{

ElecBill obj=new ElecBill();

obj.accept();

obj.calculate();

obj.print();

}

}

Similar questions