Define a class named CloudStorage with the following specifications:
Member Variables:
int acno – stores the user’s account number
int space – stores the amount of storage space in GB purchased by the user
double bill – stores the total price to be paid by the user
Member Methods:
void accept() – prompts the user to input their account number and storage space using Scanner class methods only.
void calculate() – calculates the bill total price based on the storage space purchased using the pricing table provided:
| Storage range | Price per GB (Rs) |
|---|---|
| First 15 GB | 15 |
| Next 15 GB | 13 |
| Above 30 GB | 11 |
void display() – displays the account number, storage space and bill to be paid.
Write a main method to create an object of the class and invoke the methods of the class with respect to the object.
Show SolutionHide Solution↓
import java.util.Scanner;
class CloudStorage{
int acno;
int space;
double bill;
public void accept(){
Scanner in = new Scanner(System.in);
System.out.print("Account number: ");
acno = in.nextInt();
System.out.print("Space: ");
space = in.nextInt();
}
public void calculate(){
if(space <= 15)
bill = space * 15;
else if(space <= 30)
bill = 225 + (space - 15) * 13;
else
bill = 420 + (space - 30) * 11;
}
public void display(){
System.out.println("Account No. " + acno);
System.out.println("Storage space: " + space);
System.out.println("Bill: " + bill);
}
public static void main(String[] args){
CloudStorage obj = new CloudStorage();
obj.accept();
obj.calculate();
obj.display();
}
}
