Zeek_Ch08_PractiseSet3.java


/*
 Create a class cube and write method to calculate its:
 ---totalArea
 ---Surafce area of one-face
 ---Volume
 Take the length of side as an input from user
 */

package com.company;

import java.util.Scanner;

class Cube{
    int a;//Property required
    
    //Creating methods
    public int totalArea(){
        return 6*a*a;
    }
    
    public int surfaceAreaOneFace(){
        return a*a;
    }
    
    public int volume(){
        return a*a*a;
    }
    //Methods Created
}

public class Zeek_Ch08_PractiseSet3 {
public static void main(String[] args) {
                
                Scanner sc=new Scanner(System.in);
                System.out.println("Enter the value of edge(side) of cube:");
                int m=sc.nextInt();//Getting value from user
                
                Cube calculationsnew Cube();//Instantiating the class Cube.
                
                //Setting value of a (attribute of class) with m(user input)
                calculations.a = m; 
                
                //Storing  return in integer values
                int tcalculations.totalArea();
                int scalculations.surfaceAreaOneFace();
                int vcalculations.volume();
                
                //Printing integer with stored values
                System.out.println("Total Area of cube is: "+t);
                System.out.println("Surface Area of one face of cube is: "+s);
                System.out.println("Volume of cube is:"+v);
         }
} 

Comments

Popular posts from this blog

Zeek_31_MethodInJava.java