मराठी

Define a class named CloudStorage with the following specifications: Member Variables: - Computer Applications

Advertisements
Advertisements

प्रश्न

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.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
class CloudStorage
{
  int acno;
  int space;
  double bill;
public void accept()
{
  Scanner sc=new Scanner(System.in);
  System.out.println("Enter your account
  number :");
  acno=sc.nextlnt();
  System.out.println("Enter amount of storage
  space required :");
  space=sc.nextint();
}
public void calculate()
{
 if (space<=15)
  bill=space*15
 else if(space<=30)
  bill=15*15 + (space-15)*13
else if (space>30)
  bill=15*15 + 15 *13 + (space-30)*11
}
public void display()
{
  System.out.println("Account No.: "+ acno);
  System.out.println("Storage :" + space);
  System.out.println("Bill : "+ bill);
}
public static void main(String[] args)
{
  CloudStorage ob=new CloudStorage();
  ob.accept();
  ob.calculate();
  ob.display();
}
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2024-2025 (March) Official Board
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×