Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Something Wrong With My Program
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 10-20-2009, 01:37 AM
R2Pleasent's Avatar
The GP King
$25 USD Donor Ex-Moderator Highly Trusted Sythe Verified User
 
Join Date: Feb 2007
Location: Canada!
Posts: 7,855
Send a message via MSN to R2Pleasent Send a message via Skype™ to R2Pleasent
Default Something Wrong With My Program

Here is my Constructor, compiles fine...

Code:
class Ride {
	String name;
	int ticketsRequired;
	float heightRequired;
	int numberOfRiders;
	
	Ride(String n, int tR, float hR, int numR){
		this.name = n;
		this.ticketsRequired = tR;
		this.heightRequired = hR;
		this.numberOfRiders = numR;
	}
	
	Ride(String n, int tR, float hR){
		this.name = n;
		this.ticketsRequired = tR;
		this.heightRequired = hR;
		this.numberOfRiders = 0;
	}
		
 	Ride(){
		this.name = "UNKNOWN";
		this.ticketsRequired = 0;
		this.heightRequired = 0f;
		this.numberOfRiders = 0;
	}
	public String toString() {
		return (this.name + " requiring " + this.ticketsRequired + " with a height restriction of "+this.heightRequired+"'");
	}

}

However, when I test it out, it refuses to work. Says identifier expected on each of my new Ride objects. Anyone know what I'm doing wrong?:

Code:
class RideTestProgram {
	
	Ride r1, r2;

    r1 = new Ride("Super Charger", 2, 3f);
    r2 = new Ride("Mastermind", 3, 10f);
    
    System.out.println(r1);
    System.out.println(r2);
    
    
}
__________________

Reply With Quote
  #2  
Old 10-20-2009, 02:38 AM
Jimmy's Avatar
Leecher
Ex-Moderator $5 USD Donor
 
Join Date: Jun 2008
Location: Southern California
Posts: 2,359
Default Re: Something Wrong With My Program

Your assignments and method calls must be put in a method- they can't just be out in the open like that (unless you are declaring a non-local field, in which case you can provide an assignment, but only as an initalizer in the same statment in which you declare it).

Try something along the lines of:

Code:
class RideTestProgram {

    Ride r1 = new Ride("Super Charger", 2, 3f);
    Ride r2 = new Ride("Mastermind", 3, 10f);

    public static void aMethodExample() {
	System.out.println(r1);
	System.out.println(r2);
    }

}

Last edited by Jimmy : 10-20-2009 at 02:38 AM.
Reply With Quote
  #3  
Old 10-23-2009, 06:14 AM
Guru
 
Join Date: Jan 2007
Location: /home/Canada
Posts: 1,768
Default Re: Something Wrong With My Program

Should be using a main method.

Code:
class RideTestProgram {

    public static void main(String[] args) {
        Ride r1, r2;

        r1 = new Ride("Super Charger", 2, 3f);
        r2 = new Ride("Mastermind", 3, 10f);

        System.out.println(r1);
        System.out.println(r2);
    }

}
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 04:25 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1