• Post Reply Bookmark Topic Watch Topic
  • New Topic

Very simple Program  RSS feed

 
Matt Road
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody. I am completely new to java world

Here is my first program ;



class shop {
string name;
int gain;
string good;

void speak() {System.out.println(" sono un negozio %s che guadgna %d che vende %s ", name, gain, good); }


}

public static void main ( string[] args ) {

int i;
shop[] array;

array = new shop[1];

array[0] = new shop();

array[1] = new shop();


array[0].name = "salumeria";
array[0].gain = 100;
array[0].good

array[1].name = "fruttivendolo";
array[1].gain = 200;
array[1].good = "frutta";




for (int i=0; i<2; i++) {

array[i].speak();

}

}



The compiler says that 'error: class, interface or enum expected" every time the array is proceed.

SOmeone can help me?

CHeers!!!



 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Road wrote:
The compiler says that 'error: class, interface or enum expected" every time the array is proceed.


That is a common error message that occurs when the compiler is confused -- which is generally caused by a syntax error. In this case, you declared a method outside of the class.

Henry
 
Matt Road
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the only methos is 'speak' and is inside the class 'shop'...
 
Matt Road
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok! I got it





now the error is that cannot find symbol string good, string name ecc ecc.. Can you help me ? Thank you!!!
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags (← that's a link) and indent your code properly. It will help a lot.

Java is case sensitive, so "string" is not the same as "String".
 
Matt Road
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry! Now the problem says that .printIN is not applicable..



Thank you!



 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println() takes a single parameter of type String. You appear to be trying to use a format string, but the println method doesn't do that for you.

Use System.out.println(String.format("format string goes here", argumentsGoHere));
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively

 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't PRINTIN but PRINTLN in lower‑case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!