user1534779
user1534779

Reputation: 51

Java two classes I need assistance with main method

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 ();

}

}

Upvotes: 0

Views: 145

Answers (5)

programmer33
programmer33

Reputation: 652

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);

Upvotes: 0

Chris Dargis
Chris Dargis

Reputation: 6053

public void saljbil();

Remove the semi-colon

public void saljbil()

Do the same for the kopBil() method.

Having a semi-colon at the end of a method signature disassociates the code block that follows it.

Upvotes: 1

Reimeus
Reimeus

Reputation: 159844

Just some minor adjustments required:

public void saljbil();
      remove ; here  ^

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

BTW, getAll() is not defined in class Personbil:

personbil.getAll();

Upvotes: 0

Byter
Byter

Reputation: 1132

Syntax Error

public void saljbil();

Remove ; from the method definition

Upvotes: 3

kosa
kosa

Reputation: 66657

public void saljbil(); remove the semi-colon

It should be:

 `public void saljbil()`

Upvotes: 2

Related Questions