Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ukol2;
- class Block {
- String name;
- int width, height, depth;
- Block(String n, int w, int h, int d) {
- name = n;
- width = w;
- height = h;
- depth = d;
- }
- Block() {
- name = "default";
- width = 20;
- height = 10;
- depth = 5;
- }
- void nastavRozmery(int w, int h, int d) {
- width = w;
- height = h;
- depth = d;
- }
- float objem() {
- return width * height * depth;
- }
- float povrch() {
- return 2 * (width * height + height * depth + width * depth);
- }
- float telesovaUhlopricka() {
- return (float) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2) + Math.pow(depth, 2));
- }
- void vypisInfo() {
- System.out.println("Kvádr se jmenuje " + name + ".");
- System.out.println("Výška kvádru je: " + height);
- System.out.println("Šířka kvádru je: " + height);
- System.out.println("Hloubka kvádru je: " + height);
- System.out.println("Objem kvádru je: " + objem());
- System.out.println("Povrh kvádru je: " + povrch());
- System.out.println("Tělesová úhlopříčka kvádru je: " + telesovaUhlopricka());
- }
- }
- public class Ukol2 {
- public static void main(String[] args) {
- Block block1 = new Block(), block2 = new Block("druhý",40,30,20);
- block1.vypisInfo();
- System.out.println("---------------------------------------");
- block2.vypisInfo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment