Tugas 2 PBO B

1. Class Window




2. Output Window




3. Source Code
Cube Class
/**
 * cube
 * 
 * @author Arino Jenynof
 * @version 20180910
 */

public class cube
{
    private double side;
    
    /**
     * Constructor, initialize side to 0;
     */
    public cube()
    {
        side = 0;
    }
    
    /**
     * side setter
     */
    public void set_side(double side)
    {
        this.side = side;
    }
    
    /**
     * Method to find cube's surface area
     */
    public double surface_area()
    {
        return 6*side*side;
    }
    
    /**
     * Method to find cube's volume
     */
    public double volume()
    {
        return side*side*side;
    }
}
Block Class
/**
 * block
 * 
 * @author Arino Jenynof
 * @version 20180910
 */

public class block
{
    private double length, width, height;
    
    /**
     * Constructor, initialize length, width, height to 0;
     */
    public block()
    {
        length = 0;
        width = 0;
        height = 0;
    }
    
    /**
     * length setter
     */
    public void set_length(double length)
    {
        this.length = length;
    }
    
    /**
     * width setter
     */
    public void set_width(double width)
    {
        this.width = width;
    }
    
    /**
     * height setter
     */
    public void set_height(double height)
    {
        this.height = height;
    }
    
    /**
     * Method to find block's surface area
     */
    public double surface_area()
    {
        return (2*length*width) + (2*length*height) + (2*width*height);
    }
    
    /**
     * Method to find block's volume
     */
    public double volume()
    {
        return length*width*height;
    }
}
Tube Class
/**
 * tube
 * 
 * @author Arino Jenynof
 * @version 20180910
 */

public class tube
{
    private double radius, height;
    
    /**
     * Constructor, initialize radius and height to 0;
     */
    public tube()
    {
        radius = 0;
        height = 0;
    }
    
    /**
     * radius setter
     */
    public void set_radius(double radius)
    {
        this.radius = radius;
    }
    
    /**
     * height setter
     */
    public void set_height(double height)
    {
        this.height = height;
    }
    
    /**
     * Method to find tube's surface area
     */
    public double surface_area()
    {
        return (2*3.14159*radius*radius) + (2*3.14159*radius*height);
    }
    
    /**
     * Method to find tube's volume
     */
    public double volume()
    {
        return 3.14159*radius*radius*height;
    }
}
Ball Class
/**
 * ball
 * 
 * @author Arino Jenynof
 * @version 20180910
 */

public class ball
{
    private double radius;
    
    /**
     * Constructor, initialize radius to 0;
     */
    public ball()
    {
        radius = 0;
    }
    
    /**
     * radius setter
     */
    public void set_radius(double radius)
    {
        this.radius = radius;
    }
    
    /**
     * Method to find ball's surface area
     */
    public double surface_area()
    {
        return 4*3.14159*radius*radius;
    }
    
    /**
     * Method to find ball's volume
     */
    public double volume()
    {
        return (4.0/3.0)*3.14159*radius*radius*radius;
    }
}
Main Class
/**
 * Tugas 2 PBO B
 * 
 * @author Arino Jenynof
 * @version 20180910
 */

//Enable user input
import java.util.Scanner;

public class my_main
{
    public static void main(String[] args)
    {
        //Object instantiation
        cube my_cube = new cube();
        block my_block = new block();
        tube my_tube = new tube();
        ball my_ball = new ball();
        
        //Instantiate variable to hold user input
        Scanner my_var = new Scanner(System.in);
        
        System.out.println("Input cube's side");
        my_cube.set_side(Double.parseDouble(my_var.next()));
        
        System.out.println("Input block's length, width, and height");
        my_block.set_length(Double.parseDouble(my_var.next()));
        my_block.set_width(Double.parseDouble(my_var.next()));
        my_block.set_height(Double.parseDouble(my_var.next()));
        
        System.out.println("Input tube's base radius and height");
        my_tube.set_radius(Double.parseDouble(my_var.next()));
        my_tube.set_height(Double.parseDouble(my_var.next()));
        
        System.out.println("Input ball's radius");
        my_ball.set_radius(Double.parseDouble(my_var.next()));
        
        System.out.println("Cube surface area = "+my_cube.surface_area());
        System.out.println("Cube volume = "+my_cube.volume());
        System.out.println("Block surface area = "+my_block.surface_area());
        System.out.println("Block volume = "+my_block.volume());
        System.out.println("Tube surface area = "+my_tube.surface_area());
        System.out.println("Tube volume = "+my_tube.volume());
        System.out.println("Ball surface area = "+my_ball.surface_area());
        System.out.println("Ball volume = "+my_ball.volume());
    }
}

Comments