473,421 Members | 1,553 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,421 software developers and data experts.

Class or interface expected error, any ideas!

Dφkφll
2,364 Expert 2GB
I don't want you nice guys to waste your too much of your time, and confused me in the process.

I am hoping you can explain it to me like I am 2 years old, that's it.

Hoping to get a handle on why am I getting this error "Class or interface expected error"

If you could point me to it it, ramble if you have to so I may get it, I think that'll help; of course if you want to just tell me the answer, know what I mean, hey I cannot stop you:-)

But seriously now, I do not know why I cannot modify this simple code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Book
  3. {
  4.     //
  5.     private String author;
  6.  
  7.     // …………….
  8.     private String title;
  9.     // …………….
  10.     private Int pages;
  11.  
  12.  
  13. }
  14.  
  15.    /**
  16.      * Create ……………………..
  17.      * ……………………….
  18.      * …………………………
  19.      * BELOW IS OUR CONTRUCTOR METHOD
  20.      * Line below is the line HIGHLIGHTED, in the program
  21.     */
  22.     public Book(Sring bookAuthor, String bookTitle)    
  23. {
  24.         author = bookAuthor;
  25.         title = bookTitle;
  26.                           }
  27.     public Book(Int bookPages)
  28.     {
  29.         pages = bookPages;
  30.  
  31.                           }
  32.  
  33.     /**
  34.      * Return ………………..
  35.      * BELOW IS OUR ASSESSOR
  36.      */
  37.     public String getAuthor()
  38.     {
  39.         return Author;
  40.     }
  41.  
  42.     /**
  43.      * Return …………………..
  44.      * …………………..
  45.      */
  46.  
  47.  
  48.     /**
  49.      * ……………………….
  50.      * BELOW IS OUR ASSESSOR
  51.      */
  52.     public String getTitle()
  53.     {
  54.         return Title;
  55.     }
  56.  
  57. /**
  58.      * WE HOPE TO PRINT
  59.      */
  60.     public void printAuthor()
  61.     {
  62.         // Simulate the printing of an Author.
  63.         System.out.println("##################");
  64.         System.out.println("# The Author of this book is:");
  65.         System.out.println("# Author");
  66.         System.out.println("# " + author + " extraordinaire.");
  67.         System.out.println("##################");
  68.         System.out.println();
  69.  
  70.     }
  71.  
  72.  
  73.  
Anyway, when I run, and the error pops up, there's nothing I can do but stare at it. I am not frustrated yet, but I haven't got a sense why it would do this.

I think as I said if you go so far as comparing apples to apples it should eventually sink in:-)

Thanks for your help!
Sep 27 '07 #1
10 3123
stack
40
Start by moving the curly brace from line 12 to line 70.
The curly braces at lines 2 and 70 will now contain your code, that is,
the code of the class Book. You will also need the main method to
compile it.

Also, when you declare variables, you must use small letters for the
type. Example int (not Int). Only the String type needs a capital "S"
like it is in your code.

You have declared variables author and title but then you try
to use them with different names (Author and Title).

Should I go into more depth? :-)

Cheers
stack
Sep 28 '07 #2
NeoPa
32,556 Expert Mod 16PB
Dφkφll,

You're too used to using a case-insensitive language. You need to get into the habit of worrying about the case of letters. This is not a bad habit even for the case-insensitive languages mind-you.

Good luck.
Sep 28 '07 #3
Dφkφll
2,364 Expert 2GB
unbelievable!

stack, NeoPa, thanks to you both. You know, Java did not seem to yell at me for adding Int and not int, typo without a doubt, what a moron. Must say tireness had something to do with it:-) Will give it another whirl, thanks again...
Oct 1 '07 #4
Dφkφll
2,364 Expert 2GB
No syntax errors, code compiled!

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Book
  3. {
  4.     // ……………….
  5.     private String author;
  6.  
  7.     // …………….
  8.     private String title;
  9.     // …………….
  10.     private int pages;
  11.  
  12.     private int total;
  13.  
  14.  
  15.    /**
  16.      * Create ……………………..
  17.      * ……………………….
  18.      * …………………………
  19.      * 
  20.      * 
  21.      * 
  22.      * 
  23.      * 
  24.      * 
  25.      * 
  26.      * /**
  27.      * Create a machine that issues tickets of the given price.
  28.      */
  29.     public Book(int bookPages)
  30.     {
  31.         pages = bookPages;
  32.         total = 0;
  33.     }
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.     /**
  41.      * @Return The price of a ticket.
  42.      */
  43.     public int getPages()
  44.     {
  45.         return pages;
  46.     }
  47.  
  48.  
  49.  
  50.     public Book(String bookAuthor, String bookTitle)
  51.     {
  52.         author = bookAuthor;
  53.         title = bookTitle;
  54.                           }
  55.  
  56.  
  57.     /**
  58.      * Return ………………..
  59.      * BELOW IS OUR ASSESSOR
  60.      */
  61.     public String getAuthor()
  62.     {
  63.         return author;
  64.     }
  65.  
  66.     /**
  67.      * Return …………………..
  68.      * …………………..
  69.      */
  70.  
  71.  
  72.     /**
  73.      * ……………………….
  74.      * BELOW IS OUR ASSESSOR
  75.      */
  76.     public String getTitle()
  77.     {
  78.         return title;
  79.     }
  80.  
  81.  
  82.  
  83.     /**
  84.      * Receive an amount of money in cents from a customer.
  85.      * Check that the amount is sensible.
  86.      */
  87.     public void jumpOnepage(int total)
  88.     {
  89.         if(total > 0) {
  90.             pages = pages + total;
  91.         }
  92.         else {
  93.             System.out.println("Use a positive amount: " +
  94.                                total);
  95.  
  96.  
  97.                             }
  98.                         }
  99.     public void printAuthor()
  100.     {
  101.         if(total >= pages) {
  102.  
  103.         // Simulate the printing of a ticket.
  104.         System.out.println("##################");
  105.         System.out.println("# The Author of this book is:");
  106.         System.out.println("# " + author + " extraordinaire.");
  107.         System.out.println("##################");
  108.         System.out.println();
  109.  
  110.  
  111.         // Update the total collected with the price.
  112.             total = total + pages;
  113.  
  114.     }
  115.  
  116.  
  117. public int getTotal()
  118.     {
  119.         return total;
  120.     }
  121. }
  122.  
  123.  
Thanks again, truly appreciate it. I am going to play around see what it'll do...In a bit!
Oct 1 '07 #5
JosAH
11,448 Expert 8TB
You know, Java did not seem to yell at me for adding Int and not int, typo without a doubt, what a moron.
It couldn't yell at you for that because maybe you hade defined Int as a non-public
or nested or inner class somewhere further down the file. When it saw that right
curly bracket all bets were off and only syntactic diagnostics were produced.

kind regards,

Jos
Oct 1 '07 #6
Dφkφll
2,364 Expert 2GB
It couldn't yell at you for that because maybe you hade defined Int as a non-public
or nested or inner class somewhere further down the file. When it saw that right
curly bracket all bets were off and only syntactic diagnostics were produced.

kind regards,

Jos
Cleaned it up a little bit:

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Book
  3. {
  4.     // ……………….
  5.     private String author;
  6.     // …………….
  7.     private String title;
  8.     // …………….
  9.     private int pages;
  10.     // …………….
  11.     private int fetchedpages;
  12.     // …………….
  13.     private int balance; 
  14.     // …………….
  15.     private int total;
  16.  
  17.  
  18.    /**
  19.      * Create ……………………..
  20.      * ……………………….
  21.      * …………………………
  22.      * 
  23.      */
  24.  
  25.      /**
  26.      * Create...
  27.      */
  28.     public Book(int bookPages)
  29.     {
  30.         pages = bookPages;
  31.         balance = 0;
  32.         total = 0;
  33.     }
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.     /**
  41.      * @Return....
  42.      */
  43.     public int getPages()
  44.     {
  45.         return pages;
  46.     }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.     /**
  55.      * Return number of pages already inserted...
  56.      */
  57.     public int getBalance()
  58.     {
  59.         return balance;
  60.     }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.     public Book(String bookAuthor, String bookTitle)
  69.     {
  70.         author = bookAuthor;
  71.         title = bookTitle;
  72.                           }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.      /**
  79.      * Check...
  80.      */
  81.     public void addAuthor(String author)
  82.     {
  83.         if(author != null ) {
  84.             author = author + author;
  85.         }
  86.         else {
  87.             System.out.println("Use a positive number: " +
  88.                                author);
  89.         }
  90.     }                     
  91.  
  92.  
  93.     /**
  94.      * Check...
  95.      */
  96.     public void addTitle(String title)
  97.     {
  98.         if(title != null) {
  99.             title = title + title;
  100.         }
  101.         else {
  102.             System.out.println("Use a positive number: " +
  103.                                title);
  104.         }
  105.     }                     
  106.  
  107.  
  108.  
  109.  
  110.     /**
  111.      * Return ………………..
  112.      * BELOW IS OUR ASSESSOR
  113.      */
  114.     public String getAuthor()
  115.     {
  116.         return author;
  117.     }
  118.  
  119.     /**
  120.      * Return …………………..
  121.      * …………………..
  122.      */
  123.  
  124.  
  125.     /**
  126.      * ……………………….
  127.      * BELOW IS OUR ASSESSOR
  128.      */
  129.     public String getTitle()
  130.     {
  131.         return title;
  132.     }
  133.  
  134.  
  135.     public void addpages(int pages)
  136.     {
  137.         if(pages > 0) {
  138.             balance = balance + pages;
  139.         }
  140.         else {
  141.             System.out.println("Use a positive number: " +
  142.                                pages);
  143.  
  144.  
  145.                             }
  146.                         }
  147.  
  148.  
  149.     public void guessnumberofPages(int fetchedpages)
  150.     {
  151.         if(fetchedpages <= pages) {
  152.             pages = pages - fetchedpages;
  153.         }
  154.         else {
  155.             System.out.println("The number of pages exceeded " + pages + " pages: ");
  156.             System.out.println("Where " + pages + " is the value contained within this book.");
  157.         }
  158.     }
  159.  
  160.  
  161.  
  162.     public void printAuthor()
  163.     {
  164.         if(total >= pages) {
  165.  
  166.         // ............
  167.         System.out.println("##################");
  168.         System.out.println("# The Author of this book is:");
  169.         System.out.println("# " + author + ".");
  170.         System.out.println("# " + "Author extraordinaire of " + title + ".");
  171.         System.out.println("# " + "There are " + pages + " pages " + " in this book " + ".");
  172.         System.out.println("##################");
  173.         System.out.println();
  174.  
  175.  
  176.         // ........
  177.  
  178.         total = total + pages;
  179.  
  180.     }
  181.  
  182.  
  183. public int getTotal()
  184.     {
  185.         return total;
  186.     }
  187. }
  188.  
  189.  
The only thing that isnt working is printing to system, I get:

##################
# The Author of this book is:
# Gigi.
# Author extraordinaire of Bibi.
# There are 0 pages in this book .
##################

But there are pages included, the code demands that a user inserts pages which must be then found when called.

Above code is by no means professional and I attempt to comment, please tell me why you think I cannot print the nuber of pages inserted when code is run.

You can go in detail if you want, already submitted the work. Just trying to see what I can make it do:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. /**
  4. *from here, were good, I can add pages and see that they're there through *balance.
  5. */
  6.  
  7.  
  8.     public void addpages(int pages)
  9.     {
  10.         if(pages > 0) {
  11.             balance = balance + pages;
  12.         }
  13.         else {
  14.             System.out.println("Use a positive number: " +
  15.                                pages);
  16.  
  17.  
  18.                             }
  19.                         }
  20.  
  21.  
  22.  
  23.  
  24. /**
  25. *I am using this in a totally different way than what was asked here with this bit of code.  
  26.  
  27. *This was to calculate discounted price for a ticket.  I hope to make be used for user to guess number of pages in a book.
  28.  
  29. */                     
  30.  
  31.  
  32.  
  33.     public void guessnumberofPages(int fetchedpages)
  34.     {
  35.         if(fetchedpages <= pages) {
  36.             pages = pages - fetchedpages;
  37.         }
  38.         else {
  39.             System.out.println("The number of pages exceeded " + pages + " pages: ");
  40.             System.out.println("Where " + pages + " is the value contained within this book.");
  41.         }
  42.     }
  43.  
  44.  
User must guess number of pages in the book. If incorrect will no but it will not equal to zero.

By the time we exchange notes again I would have realized what's a miss but do throw a thought here if you would. In a bit!
Oct 3 '07 #7
JosAH
11,448 Expert 8TB
I stopped reading your code when I saw this:

Expand|Select|Wrap|Line Numbers
  1.  public void addAuthor(String author)
  2.     {
  3.         if(author != null ) {
  4.             author = author + author;
  5.         }
  6.         else {
  7.             System.out.println("Use a positive number: " +
  8.                                author);
  9.         }
  10.     }      
  11.  
I saw that 'pattern' a few times more ... what is it supposed to do?

kind regards,

Jos
Oct 3 '07 #8
Dφkφll
2,364 Expert 2GB
I stopped reading your code when I saw this:

Expand|Select|Wrap|Line Numbers
  1.  public void addAuthor(String author)
  2.     {
  3.         if(author != null ) {
  4.             author = author + author;
  5.         }
  6.         else {
  7.             System.out.println("Use a positive number: " +
  8.                                author);
  9.         }
  10.     }      
  11.  
I saw that 'pattern' a few times more ... what is it supposed to do?

kind regards,

Jos
In the original code it serves as adding additional monetary amounts for the price of a book which is then compared when user enters an amount that is less than the price of the book:

Expand|Select|Wrap|Line Numbers
  1.  
  2. This code works fine for the purpose it serves...
  3.  
  4.  
  5. public void insertMoney(int amount)
  6.     {
  7.         if(amount > 0) {
  8.             balance = balance + amount;
  9.         }
  10.         else {
  11.             System.out.println("Use a positive amount: " +
  12.                                amount);
  13.         }
  14.     }
  15.  
  16.  
I was hoping to use the code to insert an author into the program, which seems to be working, no errors thus far, but when author is fetched, nothing is returned.

Above code does return value, even though the program spits out crazy when nothing is found, at least the message "Use a positive amount: " + amount..." should pop up. Gotta do something 'bout that message, does not sound right. But the code should be able to do that right, add and author. I already have a method of print anything added! Thanks for you input, you're making me think:-)
Oct 4 '07 #9
r035198x
13,262 8TB
In the original code it serves as adding additional monetary amounts for the price of a book which is then compared when user enters an amount that is less than the price of the book:

Expand|Select|Wrap|Line Numbers
  1.  
  2. This code works fine for the purpose it serves...
  3.  
  4.  
  5. public void insertMoney(int amount)
  6.     {
  7.         if(amount > 0) {
  8.             balance = balance + amount;
  9.         }
  10.         else {
  11.             System.out.println("Use a positive amount: " +
  12.                                amount);
  13.         }
  14.     }
  15.  
  16.  
I was hoping to use the code to insert an author into the program, which seems to be working, no errors thus far, but when author is fetched, nothing is returned.

Above code does return value, even though the program spits out crazy when nothing is found, at least the message "Use a positive amount: " + amount..." should pop up. Gotta do something 'bout that message, does not sound right. But the code should be able to do that right, add and author. I already have a method of print anything added! Thanks for you input, you're making me think:-)
So you are trying to port code that works for integers to work for Strings? The + operator has a different effect on Strings than it has on integers so you might need to think about that and make the neccessary adjustments.
Oct 4 '07 #10
Dφkφll
2,364 Expert 2GB
So you are trying to port code that works for integers to work for Strings? The + operator has a different effect on Strings than it has on integers so you might need to think about that and make the neccessary adjustments.
That indeed, consumed by everything else I forgot the simplest of things. Thanks much r035198x!
Oct 5 '07 #11

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

Similar topics

22
by: Marcin Vorbrodt | last post by:
Taken out of C++ In a Nutshell book... Example 7-18: Using an abstract classes as interface specification. struct Runnable { virtual void run() = 0; }; struct Hashable { virtual size_t...
14
by: Lee Franke | last post by:
I can't seem to figure this one out. Here is my class structure namespace name { public class foo { } }
3
by: JB | last post by:
My problem: I have an abstract class that implements an Interface: abstract class ReportBase: IReport { ..... Constructor and Code.... } On a user control I try to have it's class derive...
19
by: bubzilla | last post by:
Hi, i΄ve got about 10 headerfiles with implemented classes. Now when i try to compile them i get the following message: In file included from Proxy/ServerCnx.hh:36, from...
2
by: bubzilla | last post by:
Hi, i΄ve got about 10 headerfiles with implemented classes. Now when i try to compile them i get the following message: In file included from Proxy/ServerCnx.hh:36, from Proxy/Payload.hh:30,...
4
by: rach | last post by:
I just started to learn C++. I copied the following code from a data structure textbook to a ".h" file and couldn't compile it. The code contains three template interfaces. One inherits another. The...
2
by: nospam | last post by:
Hello - I am getting a compile error "Expected class, delegate, enum". I am trying to create a Class Library in C# which wraps around an unmanaged DLL that manages a MIDI interface. In my...
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
11
by: Rafe | last post by:
Hi, I'm working within an application (making a lot of wrappers), but the application is not case sensitive. For example, Typing obj.name, obj.Name, or even object.naMe is all fine (as far as...
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.