Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: In Class Problem

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default In Class Problem

    Hey my name Josh and im in a intro to java programing class as we speak and my teacher offered me extra credit if i could figure out this problem so hopefully this forum can help.

    im new to this so i applogize if this is the in the wrong format

     
    public abstract class Vehicle
    {
    	private String powerSource;
    	private int wheels;
    	protected int price;
    	public Vehicle(String powerSource, int wheels);
    	{
    		setPowerSource(powerSource);
    		setWheels(wheels);
    		setPrice();
    	}
    	public String getPowerSource()
    	{
    		return powerSource;
    	}
    	public int getWheels()
    	{
    		return wheels;
    	}
    	public int getPrice()
    	{
    		return price;
    	}
    	public void setPowerSource(String source)
    	{
    		powerSource = source;
    	}
    	public void setWheels(int wls)
    	{
    		wheels = wls;
    	}
    	public abstract void setPrice();
    }

    the error that comes up is:
    Vehicle.java:12: error: missing method body, or declare abstract
    public Vehicle(String powerSource, int wheels);


    thank you ahead of time anyone who can help me get extra credit


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: In Class Problem

    You've got a misplaced semicolon on the Vehicle constructor's top line. Get rid of it.

    Constructors should look like:

    public class MyClass {
      public MyClass(SomeType someParameter)
      {
         // stuff goes here
      }
    }

    Not:
    public class MyClass {
      public MyClass(SomeType someParameter);
      {
         // stuff goes here
      }
    }

    Notice the difference?

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: In Class Problem

    Thank you so much for the quick response and sry it was so simple

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: In Class Problem

    Quote Originally Posted by Walters View Post
    Thank you so much for the quick response and sry it was so simple
    Nothing simple about it. Sometimes you just need a fresh pair of eyes to see with. That's why I sometimes find that if I sleep on a tough problem, I can solve it in the morning with my "fresh eyes". Best of luck with your course work!

Similar Threads

  1. Replies: 5
    Last Post: October 18th, 2012, 01:43 PM
  2. problem with my class
    By Marcusjamaal in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 13th, 2012, 03:19 AM
  3. accessing class method problem
    By steel55677 in forum Object Oriented Programming
    Replies: 11
    Last Post: February 23rd, 2012, 08:50 PM
  4. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM
  5. Main Class Not Found Problem
    By shadow in forum Java Theory & Questions
    Replies: 3
    Last Post: September 29th, 2009, 09:42 AM

Tags for this Thread