DN08
This commit is contained in:
parent
8f40ed195b
commit
275cb8559d
82
src/DN08.java
Normal file
82
src/DN08.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
public class DN08 {
|
||||
static Lik[] liki;
|
||||
|
||||
public static void main(String[] args) {
|
||||
liki = new Lik[args.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String[] p = args[i].split(":");
|
||||
switch (p[0]) {
|
||||
case "kvadrat":
|
||||
liki[i] = new Kvadrat(Double.parseDouble(p[1]));
|
||||
break;
|
||||
case "pravokotnik":
|
||||
liki[i] = new Pravokotnik(
|
||||
Double.parseDouble(p[1]),
|
||||
Double.parseDouble(p[2])
|
||||
);
|
||||
break;
|
||||
case "nkotnik":
|
||||
liki[i] = new NKotnik(
|
||||
Integer.parseInt(p[1]),
|
||||
Double.parseDouble(p[2])
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println((int) skupniObseg());
|
||||
}
|
||||
|
||||
static double skupniObseg() {
|
||||
double obseg = 0;
|
||||
for (Lik lik : liki) {
|
||||
obseg += lik.obseg();
|
||||
}
|
||||
return obseg;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Lik {
|
||||
abstract public double obseg();
|
||||
}
|
||||
|
||||
class Pravokotnik extends Lik {
|
||||
double visina, sirina;
|
||||
|
||||
Pravokotnik(double visina, double sirina) {
|
||||
this.visina = visina;
|
||||
this.sirina = sirina;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double obseg() {
|
||||
return 2 * visina + 2 * sirina;
|
||||
}
|
||||
}
|
||||
|
||||
class Kvadrat extends Lik {
|
||||
double sirina;
|
||||
|
||||
Kvadrat(double sirina) {
|
||||
this.sirina = sirina;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double obseg() {
|
||||
return 4 * sirina;
|
||||
}
|
||||
}
|
||||
|
||||
class NKotnik extends Lik {
|
||||
int koti;
|
||||
double dolzinaStranice;
|
||||
|
||||
NKotnik(int koti, double dolzinaStranice) {
|
||||
this.koti = koti;
|
||||
this.dolzinaStranice = dolzinaStranice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double obseg() {
|
||||
return koti * dolzinaStranice;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user