Computer Applications
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.
Answer
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();
}
}Output
Related Questions
(a) Write the Java statement to initialize the first 6 odd numbers in a 3 × 2 array.
(b) What is the result of x[0][1] + x[2][1] of the above array?
Give the output of the following program segment and specify how many times the loop is executed.
String s = "JAVA"; for(i = 0; i < s.length(); i += 2) System.out.println(s.substring(i));Define a class to accept values into a 4 × 4 integer array. Calculate and print the NORM of the array.
NORM is the square root of sum of squares of all elements.1 2 1 3 5 2 1 6 3 6 1 2 3 4 6 3Sum of squares of elements = 1 + 4 + 1 + 9 + 25 + 4 + 1 + 36 + 9 + 36 + 1 + 4 + 9 + 16 + 36 + 9 = 201
NORM = Square root of 201 = 14.177446878757825Define a class to accept a String and print if it is a Super String or not. A String is Super if the number of uppercase letters are equal to the number of lowercase letters. [Use Character and String methods only]
Example: “COmmITmeNt”
Number of uppercase letters = 5
Number of lowercase letters = 5
String is a Super String