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: -
-
public class Book
-
{
-
//
-
private String author;
-
-
//
.
-
private String title;
-
//
.
-
private Int pages;
-
-
-
}
-
-
/**
-
* Create
..
-
*
.
-
*
-
* BELOW IS OUR CONTRUCTOR METHOD
-
* Line below is the line HIGHLIGHTED, in the program
-
*/
-
public Book(Sring bookAuthor, String bookTitle)
-
{
-
author = bookAuthor;
-
title = bookTitle;
-
}
-
public Book(Int bookPages)
-
{
-
pages = bookPages;
-
-
}
-
-
/**
-
* Return
..
-
* BELOW IS OUR ASSESSOR
-
*/
-
public String getAuthor()
-
{
-
return Author;
-
}
-
-
/**
-
* Return
..
-
*
..
-
*/
-
-
-
/**
-
*
.
-
* BELOW IS OUR ASSESSOR
-
*/
-
public String getTitle()
-
{
-
return Title;
-
}
-
-
/**
-
* WE HOPE TO PRINT
-
*/
-
public void printAuthor()
-
{
-
// Simulate the printing of an Author.
-
System.out.println("##################");
-
System.out.println("# The Author of this book is:");
-
System.out.println("# Author");
-
System.out.println("# " + author + " extraordinaire.");
-
System.out.println("##################");
-
System.out.println();
-
-
}
-
-
-
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!
10 3123
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
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.
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...
No syntax errors, code compiled!
Thanks again, truly appreciate it. I am going to play around see what it'll do...In a bit!
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
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:
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: -
-
-
/**
-
*from here, were good, I can add pages and see that they're there through *balance.
-
*/
-
-
-
public void addpages(int pages)
-
{
-
if(pages > 0) {
-
balance = balance + pages;
-
}
-
else {
-
System.out.println("Use a positive number: " +
-
pages);
-
-
-
}
-
}
-
-
-
-
-
/**
-
*I am using this in a totally different way than what was asked here with this bit of code.
-
-
*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.
-
-
*/
-
-
-
-
public void guessnumberofPages(int fetchedpages)
-
{
-
if(fetchedpages <= pages) {
-
pages = pages - fetchedpages;
-
}
-
else {
-
System.out.println("The number of pages exceeded " + pages + " pages: ");
-
System.out.println("Where " + pages + " is the value contained within this book.");
-
}
-
}
-
-
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!
I stopped reading your code when I saw this: -
public void addAuthor(String author)
-
{
-
if(author != null ) {
-
author = author + author;
-
}
-
else {
-
System.out.println("Use a positive number: " +
-
author);
-
}
-
}
-
I saw that 'pattern' a few times more ... what is it supposed to do?
kind regards,
Jos
I stopped reading your code when I saw this: -
public void addAuthor(String author)
-
{
-
if(author != null ) {
-
author = author + author;
-
}
-
else {
-
System.out.println("Use a positive number: " +
-
author);
-
}
-
}
-
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: -
-
This code works fine for the purpose it serves...
-
-
-
public void insertMoney(int amount)
-
{
-
if(amount > 0) {
-
balance = balance + amount;
-
}
-
else {
-
System.out.println("Use a positive amount: " +
-
amount);
-
}
-
}
-
-
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:-)
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: -
-
This code works fine for the purpose it serves...
-
-
-
public void insertMoney(int amount)
-
{
-
if(amount > 0) {
-
balance = balance + amount;
-
}
-
else {
-
System.out.println("Use a positive amount: " +
-
amount);
-
}
-
}
-
-
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.
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!
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
{
}
}
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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: 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 projectplanning, coding, testing,...
|
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...
| | |