473,418 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Not sure what is wrong with this code

Expand|Select|Wrap|Line Numbers
  1. public class Car
  2. {
  3.  
  4.    public final static int PARK = 0;
  5.    public final static int REVERSE = 1;
  6.    public final static int NUETRAL = 2;
  7.    public final static int DRIVE = 3;
  8.  
  9.    private int Speed = 0;
  10.    private int Gear = PARK;
  11.    private boolean On = false;
  12.    private String Make = Dodge;
  13.    private String Model = Caravan;
  14.    private String color = white;
  15.  
  16.    public class Car()
  17.    {
  18.    }
  19.  
  20.    public class Car(String newmake, String newmodel)
  21.    {
  22.        Make = newmake;
  23.        Model = newmodel;
  24.    }
  25.  
  26.    public class Car(String newcolor, String newmake, String newmodel)
  27.    {
  28.      Make = newmake;
  29.      Model = newmodel;
  30.      color = newcolor;
  31.    }
  32.  
  33.    public String getMake()
  34.    {
  35.       return Make;
  36.    }
  37.  
  38.    public String getModel()
  39.    {
  40.       return Model;
  41.    }
  42.  
  43.    public String getcolor()
  44.    {
  45.        return color;
  46.    }
  47.  
  48.    public void setcolor(String newcolor)
  49.    {
  50.        if(!color.equals(newcolor))
  51.  
  52.        color = "Repainted to" + newcolor;
  53.    }
  54.  
  55.    public boolean isOn()
  56.    {
  57.      return On;
  58.    }
  59.  
  60.    public void setOn(boolean OnOrOff)
  61.    {
  62.        On = OnOrOff;
  63.    }
  64.  
  65.    public int getSpeed()
  66.    {
  67.        return Speed;
  68.    }
  69.  
  70.    public void setSpeed(int newspeed)
  71.    {
  72.       if (Gear == DRIVE || Gear == REVERSE)
  73.  
  74.       Speed = newspeed;
  75.    }
  76.  
  77.    public void setGear(int newgear)
  78.    {
  79.        if(Speed == 0)
  80.  
  81.        Gear = newgear;
  82.    }
  83.  
  84.    public String getGear()
  85.    {
  86.          String CurrentGear = null;
  87.  
  88.       switch (Gear)
  89.       {
  90.          case PARK: CurrentGear = "Park";
  91.            break;
  92.            case REVERSE: CurrentGear = "Reverse";
  93.            break;
  94.            case NEUTRAL: CurrentGear = "Neutral";
  95.            break;
  96.            case DRIVE: CurrentGear = "Drive";
  97.            break;
  98.       }
  99.          return CurrentGear;
  100.    }
  101.  
  102.    public String toString()
  103.    {
  104.       String running;
  105.  
  106.       if(On)
  107.  
  108.       running = "Running";
  109.  
  110.       else
  111.  
  112.       running = "Not Running";
  113.  
  114.       return "This Car is a " + color +", " + Make + " " + Model + ".\n"
  115.       + "It is in" + getGear() + " with a speed of " + Speed + "\n"
  116.       + "and currently is" + getOn();
  117.    }
  118.  
  119. }
  120.  
  121.  
these are the errors i'm getting

C:\Users\Ben's Vaio\Desktop\Car.java:16: '{' expected
public class Car()
^
C:\Users\Ben's Vaio\Desktop\Car.java:20: '{' expected
public class Car(String newmake, String newmodel)
^
C:\Users\Ben's Vaio\Desktop\Car.java:22: <identifier> expected
Make = newmake;
^
C:\Users\Ben's Vaio\Desktop\Car.java:23: <identifier> expected
Model = newmodel;
^
C:\Users\Ben's Vaio\Desktop\Car.java:26: '{' expected
public class Car(String newcolor, String newmake, String newmodel)
^
C:\Users\Ben's Vaio\Desktop\Car.java:28: <identifier> expected
Make = newmake;
^
C:\Users\Ben's Vaio\Desktop\Car.java:29: <identifier> expected
Model = newmodel;
^
C:\Users\Ben's Vaio\Desktop\Car.java:30: <identifier> expected
color = newcolor;
^
8 errors

Tool completed with exit code 1

Thanks for the Help!
Oct 22 '10 #1
1 1137
Dheeraj Joshi
1,123 Expert 1GB
You should not use keyword class in the constructor declaration. Your code should look like this

Expand|Select|Wrap|Line Numbers
  1. public class Test{
  2.  
  3.    // Variables here
  4.  
  5.    public Test(){
  6.       //Code goes here
  7.    }
  8.    public Test(int a,int b){
  9.       // Code goes here
  10.    }   
  11. }
  12.  
Regards
Dheeraj Joshi
Oct 22 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kewlb | last post by:
Hey Guys, My server decided to all of a sudden stop giving me compile/scrip errors and instead now just gives me a blank page with no informatio as to what the problem might be. I have looked...
21
by: Jenski182 | last post by:
Is this from a good coder? or a rubbish one? Whichever way, it was paid for his services, just want to know if its worth while.... Thanks Jen x #include <iostream.h> #include <conio.h>
1
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning...
6
by: doncee | last post by:
This is the set up: is a date field on a form. Its control source is the field "date_entered" in"Table1". If there is a date showing in the date_entered field (Text6) & the status in Combo box2...
7
by: sophie | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo { private:
8
by: RompStar | last post by:
I am in the learning stages on MS Access and VBA for access, know more about some parts then others. But it dones't look that bad, the VBA, because I am used to VBA for Excel, but I am not sure...
1
by: Larry Epn | last post by:
I've created a project from Microsoft's "club.vsi". I don't want inline code so I've separated all aspx and ascx pages into code-behind pages. I'm compiling the project and continue to get this...
6
by: foonicate | last post by:
I apologize if I posted this to the wrong group. I am working with C code that (atm) draws a 2d polygon with an exclusion polygon in the center. There are points located throughout the polygon...
3
by: Koliber (js) | last post by:
I feel i still do not understand maybe a bit a dispose pattern So I have a question - is this code right? Is fs.Close() there where it is right? If I do understand it in place 'BBB' there can be a...
3
by: qianz99 | last post by:
Hi I am not sure what this code does. I have the following questions 1. where is the case? 2. #define TLV_INTEGER(name, octets) p->name = -1; Is it define a function TLV_INTEGER(name, octets) ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.