Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package butorgyar;
- public class butorlap {
- private int hossz;
- private int szel;
- private boolean tipus;
- public static final int tartoLap = 5000;
- public static final int hatLap = 500;
- public butorlap(int hossz, int szel, boolean tipus){
- this.hossz = hossz/100;
- this.szel = szel/100;
- this.tipus = tipus;
- }
- public int arSzamol(){
- return this.hossz*this.szel*((this.tipus == true)?butorlap.tartoLap:butorlap.hatLap);
- }
- }
- ------------------
- public class butor {
- private int lapokSzama;
- private butorlap[] butor;
- public butor(){
- this.lapokSzama = 0;
- this.butor = new butorlap[100];
- }
- public void setLapokSzama(int lapokSzama){
- this.lapokSzama = lapokSzama;
- }
- public void hozzaAd(butorlap b){
- butorlap[] ujButor = new butorlap[butor.length+1];
- for (int i=0; i < butor.length;i++){
- ujButor[i] = butor[i];
- }
- ujButor[ujButor.length-1] = b;
- butor = ujButor;
- }
- public int arSzamol(){
- int sum = 0;
- for(int i=0; i < butor.length;i++){
- sum = sum + butor[i].arSzamol();
- }
- return sum;
- }
- }
- ------------------
- import butorgyar.*;
- public class foo {
- public static void main(String[] args){
- butor b1 = new butor();
- butorlap bl1 = new butorlap(200,300,false);
- b1.setLapokSzama(10);
- b1.hozzaAd(bl1);
- System.out.println(b1.arSzamol());
- }
- }
- ------------------
- Exception in thread "main" java.lang.NullPointerException
- at butorgyar.butor.arSzamol(butor.java:34)
- at foo.main(foo.java:10)
- Java Result: 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement