0

in the main method what do I write in order to create a new bilagare

the format needs to be (String, String, personbil)

bilagare a = new bilagare (name, adress, AND WHAT DO I WRITE HERE TO GIVE the object one of the cars created );

public class bilagare 
{
        Personbil personbil;

        private String namn;
        private String adress;

    // konstruktor
        public bilagare (Personbil personbil, String namn, String adress)
            {
             this.personbil=personbil;
             this.namn= namn;
             this.adress = adress;

            }
    // returnerar namn
        public String hamtaNamn()
            {
            return namn;
            }

    // returnerar adress
        public String hamtaAdress()
            {
            return adress;
            }  

        public void saljbil()
        {

                if (personbil==null)
                {   
                System.out.println("Du har ingen bil att sälja");
                }

                else
                {
                System.out.println("Tackar och bugar för bilen");
                personbil = null;
                }
        }

            public void kopBil (String bilmodell, int hamtaarsmodell,String hamtaregnr, String bilfarg)
            {

                System.out.println("tack för ditt bilköp");
                personbil = new Personbil(bilmodell, hamtaarsmodell, hamtaregnr,bilfarg);       


            }         
          public void infoBil()
          {
            if (personbil==null)
            System.out.println("Äger ingen bil för närvarande");
            else
            personbil.SkrivutInfo();
         }

            public void infoAgare()
            {
             System.out.println("förarinfo\nNamn" + namn +"Adress,"+adress);

            }


public static void main (String [] args)
        {

        Personbil bil1 = new Personbil("Saab",90, "CCC222", "röd");
        Personbil bil2 = new Personbil("Volvo",99, "ABC988", "svart");

        bilagare a = new bilagare ();

}

}
4

5 回答 5

3
Syntax Error

public void saljbil();

消除 ; 从方法定义

于 2012-08-08T18:16:02.967 回答
2

public void saljbil(); remove the semi-colon

It should be:

 `public void saljbil()`
于 2012-08-08T18:14:37.193 回答
1
public void saljbil();

去掉分号

public void saljbil()

对方法执行相同的kopBil()操作。

在方法签名的末尾有一个分号会解除它后面的代码块的关联。

于 2012-08-08T18:15:30.830 回答
0
This is probably what you want, even though you should fix all your errors that have been suggested beforehand;

bilagare a = new bilagare (*string*, *string*, bil1);
    bilagare a = new bilagare (*string*, *string*, bil2);
于 2012-08-08T19:42:23.533 回答
0

只需要一些小的调整:

public void saljbil();
      remove ; here  ^

public void kopBil (String bilmodell, etc.);
                            remove ; here  ^

顺便说一句,getAll()在 Personbil 类中没有定义:

personbil.getAll();
于 2012-08-08T18:17:00.440 回答