Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class Proizvod{
- private int tezina;
- private double cena;
- private int lager;
- Proizvod(int tezina, double cena, int lager){
- this.tezina = tezina;
- this.cena = cena;
- this.lager = lager;
- }
- public int getTezina(){
- return tezina;
- }
- public void setTezina(int tezina){
- this.tezina = tezina;
- }
- public double getCena(){
- return cena;
- }
- public void setCena(double cena){
- this.cena = cena;
- }
- public int getLager(){
- return lager;
- }
- public void setLager(int lager){
- this.lager = lager;
- }
- public String toString(){
- StringBuilder sb = new StringBuilder();
- sb.append(getClass().getName()).append(" tezina: ").append(tezina)
- .append(" cena: ").append(cena)
- .append(" lager: ").append(lager).append(".;\n");
- return sb.toString();
- }
- public void zvakni(int i) {
- // TODO Auto-generated method stub
- }
- }
- class Burek extends Proizvod{
- private String fil;
- Burek(int tezina,double cena,int lager){
- super(tezina,cena,lager);
- fil = null;
- }
- public void filuj(String fil){
- this.fil = fil;
- setCena(getCena()+10.0);
- }
- public void smazi(){
- setLager(0);
- }
- public String toString(){
- StringBuilder sb = new StringBuilder();
- if(fil == null){
- sb.append(getClass().getName()).append(" tezina: ").append(getTezina())
- .append(" cena: ").append(getCena())
- .append(" lager: ").append(getLager()).append(" fill je prazan").append(".;\n");
- } else {
- sb.append(getClass().getName()).append(" tezina: ").append(getTezina())
- .append(" cena: ").append(getCena())
- .append(" lager: ").append(getLager()).append(" fil: ").append(fil).append(".;\n");
- }
- return sb.toString();
- }
- }
- class Pecivo extends Proizvod{
- Pecivo(int tezina,double cena,int lager){
- super(tezina,cena,lager);
- }
- public void zvakni(int k){
- if(getLager() >= k){
- setLager(getLager()-k);
- } else {
- setLager(0);
- }
- }
- }
- class Kroasan extends Proizvod{
- Kroasan(double cena, int lager){
- super(100,cena,lager);
- }
- public void zvakni(){
- super.zvakni(100);
- }
- }
- public class Pekara{
- public static void main(String[] args)throws Exception{
- Burek[] nizBurek;
- BufferedReader bf = new BufferedReader(new FileReader("ovo.txt"));
- System.out.println("Pocetak izvrsavanja programa");
- int brElem = Integer.parseInt(bf.readLine());
- nizBurek = new Burek[brElem];
- for(int i = 0; i < brElem; i++){
- nizBurek[i] = new Burek(Integer.parseInt(bf.readLine()),
- Double.parseDouble(bf.readLine()),Integer.parseInt(bf.readLine()));
- nizBurek[i].filuj(bf.readLine());
- }
- bf.close();
- for(int i = 0; i < brElem; i++){
- System.out.println(nizBurek[i].toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement