2013-02-03 6 views
0

Im essayant d'obtenir de l'aide pour exécuter avec mon compilateur automobile je chaned quelques choses et j'ai 1 erreurEssayer de mettre en œuvre une classe

public class AutomobileDescription 
{ 
    /** 
    Constructor to display the make, model and price the new automobile I wish to purchase 
    */ 

    public AutomobileDescription(String carMake, String carModel, carPrice) 
    { 
     make = m; 
     model = mo; 
     price = p; 
    } 
    public String m =("Toyota"); 
    public String mo =("Camry"); 
    public String p =("22055"); 

    public String getAutomobileinfo() 
    { 
    return m + mo + p; 
    Automobile myAutomobile = new Automobile(Toyota, Camry, 22055); 
    System.out.println("The Make, Model and Price of the car is: m + mo + p "); 

    } 
} 

---- jGRASP exec: javac -g AutomobileDescription.java

AutomobileDescription.java:7: error: attendu AutomobileDescription publique (String carMake, String carModel, carPrice) ^ 1 erreur

---- jGRASP wedge2: code de sortie fo Le processus r est 1. ---- jGRASP: opération terminée.

+0

Avez-vous un problème? – SLaks

+2

Les méthodes sont supposées avoir des noms, qui ne peuvent contenir que des lettres, des chiffres ou des traits de soulignement. – SLaks

+0

En outre, vous devez fournir l'implémentation 'getMake',' getModel' et 'getPrice'. – Vulcan

Répondre

1

Vous avez plusieurs problèmes ici:

public class AutomobileDescription 
{ 
    /** 
    Constructor to display the make, model and price the new automobile I wish to purchase 
    */ 

public AutomobileDescription(String carMake, String carModel, /*no return type*/ carPrice) 
{ 
    make = m; 
    model = mo; 
    price = p; 
} 
public String m =("Toyota"); 
public String mo =("Camry"); 
public String p =("22055"); 

    public String getAutomobileinfo() 
    { 
    return m + mo + p; /*return? then why statements after this?*/ 
    Automobile myAutomobile = new Automobile(Toyota, Camry, 22055); 
    System.out.println("The Make, Model and Price of the car is: m + mo + p "); 

    } 
} 

Solution:

public class AutomobileDescription{ 
/** 
Constructor to display the make, model and price the new automobile I wish to purchase 
*/ 

public AutomobileDescription(String carMake, String carModel, String carPrice) 
{ 
    m = make; 
    mo = model; 
    p = carPrice; 
} 
private String m; 
private String mo; 
private String p; 

public String getAutomobileinfo() 
{ 
    return m + mo + p; 
} 
public static void main(String[] args){ 
    AutomobileDescription myAutomobile = new AutomobileDescription("Toyota", "Camry", "22055"); 
    System.out.println("The Make, Model and Price of the car is: " + myAutomobile.getAutomobileinfo()); 
} 
} 
+0

Merci qui a beaucoup aidé –

+0

Cool @shepcleveland - obtenir un bon livre sur Java :-) .. et pirater votre chemin à l'intérieur. –

0

Ce n'est pas un nom de méthode valide:

public String getMake + getModel + getPrice; 

correctif. Si vous avez encore des problèmes, soyez un peu plus détaillé. Peut-être même poster le message d'erreur!

+0

Honnêtement, ça se voit un peu. En ce qui concerne ma réponse, un nom de méthode ne peut pas avoir des signes «+» comme ça. Vous pouvez dire 'public String getAllDetails {' et cela devrait fonctionner. Cela ne veut toujours pas dire qu'il n'y a pas plus d'erreurs là-dedans. – mrunion

1
public AutomobileDescription(String carMake, String carModel, carPrice) 
                   ^^^^^^^^ 

Vous avez omis le type du paramètre carPrice. Très probablement, vous voulez

public AutomobileDescription(String carMake, String carModel, BigDecimal carPrice) 

Un autre problème ...

public String getAutomobileinfo() 
{ 
    return m + mo + p; 
    Automobile myAutomobile = new Automobile(Toyota, Camry, 22055); 
    System.out.println("The Make, Model and Price of the car is: m + mo + p "); 
} 

La déclaration return signifie que les deux énoncés suivants ne peuvent jamais être atteints, et cela se traduira par une erreur de compilation après avoir corrigé la première problème.

+0

J'ai mentionné exactement les mêmes choses: -P ... –

+0

si vous voyez 'Automobile (Toyota, Camry, 22055);' a aussi des problèmes .. qu'est-ce que l'automobile? qu'est-ce que Toyota, qu'est-ce que Camry? 22055 n'est pas une chaîne .. ?? L'OP semble complètement ignorant de ce qu'il est en train de faire. –

+0

Vous et moi écrivions nos réponses en même temps. Vérifiez les horodatages. –

Questions connexes