Advertisement
Guest User

Java bútor

a guest
Mar 3rd, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package butorgyar;
  2.  
  3.  
  4. public class butorlap {
  5.     private int hossz;
  6.     private int szel;
  7.     private boolean tipus;
  8.    
  9.     public static final int tartoLap = 5000;
  10.     public static final int hatLap = 500;
  11.    
  12.     public butorlap(int hossz, int szel, boolean tipus){
  13.         this.hossz = hossz/100;
  14.         this.szel = szel/100;
  15.         this.tipus = tipus;
  16.     }
  17.    
  18.     public int arSzamol(){
  19.         return this.hossz*this.szel*((this.tipus == true)?butorlap.tartoLap:butorlap.hatLap);
  20.     }
  21.    
  22. }
  23. ------------------
  24. public class butor {
  25.     private int lapokSzama;
  26.     private butorlap[] butor;
  27.    
  28.     public butor(){
  29.         this.lapokSzama = 0;
  30.         this.butor = new butorlap[100];
  31.     }
  32.    
  33.     public void setLapokSzama(int lapokSzama){
  34.         this.lapokSzama = lapokSzama;
  35.     }
  36.    
  37.     public void hozzaAd(butorlap b){
  38.         butorlap[] ujButor = new butorlap[butor.length+1];
  39.         for (int i=0; i < butor.length;i++){
  40.             ujButor[i] = butor[i];
  41.         }
  42.         ujButor[ujButor.length-1] = b;
  43.         butor = ujButor;
  44.     }
  45.    
  46.     public int arSzamol(){
  47.         int sum = 0;
  48.         for(int i=0; i < butor.length;i++){
  49.             sum = sum + butor[i].arSzamol();
  50.         }
  51.        
  52.         return sum;
  53.     }
  54. }
  55. ------------------
  56. import butorgyar.*;
  57.              
  58. public class foo {
  59.     public static void main(String[] args){
  60.         butor b1 = new butor();
  61.         butorlap bl1 = new butorlap(200,300,false);
  62.         b1.setLapokSzama(10);
  63.         b1.hozzaAd(bl1);
  64.         System.out.println(b1.arSzamol());
  65.     }
  66. }
  67. ------------------
  68. Exception in thread "main" java.lang.NullPointerException
  69.     at butorgyar.butor.arSzamol(butor.java:34)
  70.     at foo.main(foo.java:10)
  71. Java Result: 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement