Results 1 to 3 of 3
  1. #1
    maz22 is offline Member
    Join Date
    Oct 2010
    Posts
    6
    Rep Power
    0

    Default Java class problem

    Hi I have a problem with this code:


    Java Code:
    package javaapplication18;
    
    import naprendszer.*;
    import java.util.LinkedList;
    import java.util.List;
    
    public class NaprendszerMain {
    
        public static void main( String args[] ){
    
            Nap nap = new Nap(332900);
    
            List<Bolygo> bolygok = new LinkedList<Bolygo>();
            Bolygo merkur = new Bolygo("Merkúr", 57.9, false, 0.055, 4864.0, 0, 87.97);
            bolygok.add(merkur);
            Bolygo venusz = new Bolygo("Vénusz", 108.2, false, 0.82, 12103.0, 0, 224.7);
            bolygok.add(venusz);
            Bolygo fold = new Bolygo("Föld", 149.6, false, 1.0, 12756.0, 1, 365.25636);
            bolygok.add(fold);
            Bolygo mars = new Bolygo("Mars", 227.9, false, 0.11, 6768.0, 2, 675.72);
            bolygok.add(mars);
            Bolygo jupiter = new Bolygo("Jupiter", 778.3, true, 318, 142948.0, 63, 4331.9);
            bolygok.add(jupiter);
            Bolygo szaturnusz = new Bolygo("Szaturnusz", 1429, true, 95.18, 120536.0, 61, 10760.45);
            bolygok.add(szaturnusz);
            Bolygo uranusz = new Bolygo("Uránusz", 2869.6, true, 14.5, 51118.0, 27, 30685.18);
            bolygok.add(uranusz);
            Bolygo neptunusz = new Bolygo("Neptunusz", 4496.6, true, 17.14, 49528.0, 13, 60190.59);
            bolygok.add(neptunusz);
    
            NapRendszer nr = new NapRendszer(nap, bolygok);
    
            System.out.println("Naprendszer");
            System.out.println(" A nap tömege: " + nr.getNap().getTomeg());
            System.out.println(" Bolygók");
    
            for( int i = 0; i < nr.getBolygok().size(); ++i ){
                Bolygo b = nr.getBolygok().get( i );
                System.out.println("  " + b.getNev() );
                System.out.println("   naptól mért távolsága: " + b.getNaptolMertTavolsag() + " millió km");
                System.out.println("   " + (b.isGazBolygo() ? "" : "nem ") + "gázbolygó");
                System.out.println("   tömege " + b.getTomeg() + "-szerese a Földének");
                System.out.println("   legnagyobb átmérője: " + b.getAtmero() + " km");
                System.out.println("   holdjainak száma: " + b.getHoldakSzama());
                System.out.println("   keringési ideje: " + b.getKeringesiIdo() + " földi nap");
            }
        }
    }

    Bolygo.java
    Java Code:
    package naprendszer;
    
    import java.util.*;
    
    public class Bolygo extends NapRendszer {
        private static int darab = 0;
        protected String nev;
        protected double naptolMertTavolsag;
        protected boolean gazBolygo;
        protected double tomeg;
        protected double atmero;
        protected int holdakSzama;
        protected double keringesiIdo;
    
    
    
        public Bolygo(String nev, double naptolMertTavolsag, boolean gazBolygo, double tomeg, double atmero, int holdakSzama, double keringesiIdo)
        {
            this.nev=nev;
            this.naptolMertTavolsag = naptolMertTavolsag;
            this.gazBolygo = gazBolygo;
            this.tomeg = tomeg;
            this.atmero = atmero;
            this.holdakSzama = holdakSzama;
            this.keringesiIdo = keringesiIdo;
            
            darab++;
        }
    
        public double getNaptolMertTavolsag() {
            return naptolMertTavolsag;
        }
    
        public boolean isGazBolygo() {
            return gazBolygo;
        }
    
        public double getTomeg() {
            return tomeg;
        }
    
        public double getAtmero() {
            return atmero;
        }
    
        public int getHoldakSzama() {
            return holdakSzama;
        }
    
        public double getKeringesiIdo() {
            return keringesiIdo;
        }
    
        public String getNev(){
            return nev;
        }
    
        public Bolygo getBolygok(){
            return bolygok;
        }
    
        public static int darab()   { return darab; }
    
        //protected double szorzó()   { return szorzó; }
    
    }
    Nap.java
    Java Code:
    package naprendszer;
    
    import java.util.*;
    
    public class Nap extends NapRendszer {
    
        private double tomeg;
    
        public Nap(double tomeg)
        {
            this.tomeg=tomeg;
        }
    
        public double getTomeg() {
            return tomeg;
        }
    
    }
    Naprendszer.java
    Java Code:
    package naprendszer;
    
    import java.util.*;
    
    public class NapRendszer {
        protected Nap nap;
        protected Bolygo bolygok;
    
        public NapRendszer(Nap nap, Bolygo bolygok){
            this.nap=nap;
            this.bolygok=bolygok;
        }
    
        public Nap getNap(Nap nap){
            return nap;
        }
    
        public Bolygo getBolygok(Bolygo bolygok){
            return bolygok;
        }
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    Quote Originally Posted by maz22 View Post
    Hi I have a problem
    not just one.....

    - NapRendszer hasnt a default constructor, so you must invoke another constructor in Naps and Bolygo constructor (super(...., ....));
    - in your main method you want to instantiate a NapRendszer object
    (NapRendszer nr = new NapRendszer(nap, bolygok); ) but the second argument is wrong (the constructor wants a Bolygo object, not a list of Bolygo objects..)
    - nr.getNap() ... look at the methods signature: public Nap getNap(Nap nap){ - the same at public Bolygo getBolygok(Bolygo bolygok) ...your foor loops make no sense (size() ??? get() ?? these are not defined in the Bolygo class)...

    ...puh...

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Hi I have a problem with this code:
    So sorry, my crystal ball's under maintenance. Without it, I'm lost trying to guess what the problem is.

    db

Similar Threads

  1. Replies: 0
    Last Post: 04-04-2010, 10:06 AM
  2. Problem in Java Class Loading process
    By gppme in forum Advanced Java
    Replies: 4
    Last Post: 04-18-2009, 04:04 AM
  3. Replies: 8
    Last Post: 03-21-2009, 09:34 AM
  4. problem calling function from class to class
    By alin_ms in forum New To Java
    Replies: 3
    Last Post: 12-19-2008, 07:35 PM
  5. Im new to java. how do i fix the problem with class
    By lexlukkia in forum New To Java
    Replies: 2
    Last Post: 11-18-2007, 04:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •