michael_hartman_cz

PedF UK - OKB1319306 Ukol2

Oct 17th, 2014
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. package ukol2;
  2. class Block {
  3.  
  4.         String name;
  5.         int width, height, depth;
  6.  
  7.         Block(String n, int w, int h, int d) {
  8.             name = n;
  9.             width = w;
  10.             height = h;
  11.             depth = d;
  12.         }
  13.  
  14.         Block() {
  15.             name = "default";
  16.             width = 20;
  17.             height = 10;
  18.             depth = 5;
  19.         }
  20.  
  21.         void nastavRozmery(int w, int h, int d) {
  22.             width = w;
  23.             height = h;
  24.             depth = d;
  25.         }
  26.  
  27.         float objem() {
  28.             return width * height * depth;
  29.         }
  30.  
  31.         float povrch() {
  32.             return 2 * (width * height + height * depth + width * depth);
  33.         }
  34.  
  35.         float telesovaUhlopricka() {
  36.             return (float) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2) + Math.pow(depth, 2));
  37.         }
  38.  
  39.         void vypisInfo() {
  40.             System.out.println("Kvádr se jmenuje " + name + ".");
  41.             System.out.println("Výška kvádru je: " + height);
  42.             System.out.println("Šířka kvádru je: " + height);
  43.             System.out.println("Hloubka kvádru je: " + height);
  44.             System.out.println("Objem kvádru je: " + objem());
  45.             System.out.println("Povrh kvádru je: " + povrch());
  46.             System.out.println("Tělesová úhlopříčka kvádru je: " + telesovaUhlopricka());
  47.         }
  48.     }
  49.  
  50. public class Ukol2 {
  51.  
  52.     public static void main(String[] args) {
  53.         Block block1 = new Block(), block2 = new Block("druhý",40,30,20);
  54.         block1.vypisInfo();
  55.         System.out.println("---------------------------------------");
  56.         block2.vypisInfo();
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment