*/
import java.io.*;
public class DriverBuggy
{
public static void main(String args[]) throws IOException
{
Buggy app;
app = new Buggy();
app.appMain();
} // end of main()
} // end of class Driver

class Buggy
{
/* Instance Data Declarations */
BufferedReader stdin;	// define stdin
int firstVar, secondVar, thirdVar;
/* appMain method calls for initialization, processing, output */
public void appMain() throws IOException;
{
stdin = new BufferedReader
(new InputStreamReader(System.in));
// create input string object
FirstVar = 11;
secondVar = 22;
thirdVar = 33;
while(firstVar < 18)
{
System.out.println("Calling the calc method.");
calc();
}
}	// end of appMain()

/* calc method calls for comparisons, calculations & detail output */
void calc()
{
if(firstVar < 13)
{
System.out.println("firstVar is " + firstVar + \n");
firstVar = firstVar + 1;
}
else
{
System.out.println("firstVar is 13" or greater. n);
firstVar = firstVar + 2;
secondVar = secondVar - 1;
firstVar + secondVar = thirdVar;
}
}	// end of calc()

/* reportOut method does the final output /*
void reportOut()
{
System.out.println("\nFINAL REPORT");
System.out.println("------------");
System.out.println("firstVar is " + firstVar);
System.out.println("secondVar is " + secondVar);
System.out.println("thirdVar is " + thirdVar);
if(firstVar < 11);
{
System.out.println("THIS SHOULD NOT PRINT");
}
} // end of class Buggy

Can someone help find whats wrong with this the error message on clem is saying ')' expected
Can some please help me!!!

System.out.println("firstVar is " + firstVar + \n");

You need an even number of quotes inside the parentheses. You're doing println, so it adds a newline character. Unless you want two of them, leave the '\n' off. firstVar probably needs to be converted to a string before adding it to a string.

System.out.println("firstVar is 13" or greater. n);

'or greater .n' is just hanging out in the middle of nowhere here. You want it inside the quotes:

System.out.println("firstVar is 13 or greater.");

I am having the same problem at line 57 for me.

/*
DriverBuggy.java
Source Name:    DriverBuggy.java
Date Written:   12/27/06
Written By:     Annette Lege
Revised By:     

Purpose:  To identify and fix common syntax errors and one
logic error in a Java program.
*/
import java.io.*;
public class DriverBuggy
{
    public static void main(String args[]) throws IOException
    {
        Buggy app;
        app = new Buggy();
        app.appMain();
    }   // end of main()
}

class Buggy
{
    /* Instance Data Declarations */
    BufferedReader stdin;   // define stdin
    int firstVar, secondVar, thirdVar;
    /* appMain method calls for initialization, processing, output */
    public void appMain() throws IOException
    {
        stdin = new BufferedReader
                (new InputStreamReader(System.in));
                // create input string object
        firstVar = 11;
        secondVar = 22;
        thirdVar = 33;
        while(firstVar < 18)
        {
            System.out.println("Calling the calc method.");
            calc();
        }
    }   // end of appMain()

    /* calc method calls for comparisons, calculations & detail output */
    void calc()
    {
        if(firstVar < 13)
        {
            System.out.println("firstVar is" + firstVar + 
"/n");
            firstVar = firstVar + 1;
        }
        else
        {
            System.out.println("firstVar is 13 or greater./n");
            firstVar = firstVar + 2;
            secondVar = secondVar - 1;
            [COLOR="Red"]firstVar + secondVar = thirdVar;[/COLOR]
        }
    }   // end of calc()

    /* reportOut method does the final output */
    void reportOut()
    {
        System.out.println("\nFINAL REPORT");
        System.out.println("------------");
        System.out.println("firstVar is " + firstVar);
        System.out.println("secondVar is " + secondVar);
        System.out.println("thirdVar is " + thirdVar);
        if(firstVar < 11);
        {
            System.out.println("THIS SHOULD NOT PRINT");
        }
    }
}
// end of class Buggy

It tells me

DriverBuggy.java:57: unexpected type
required: variable
found: value
firstVar + secondVar = thirdVar
            ^
1 error.

does it need a double +? I thought it only needed that if it was displaying that value?

"thirdValue" needs to be on the left side of the assignment operator in the form variable = <expression>

Unless it wasn't completely obvious with my very basic question I'm a total newb at this.
If I understand you correctly you are saying that it should read
thirdVar = firstVar + secondVar
?

Is that correct or am I missing the utterly obvious?

Yes, that's correct. You want to set "thirdVar" equal to the expression "firstVar + secondVar".

That worked-it finally compiled. Thanks for the help. Now to execute.

@OP

what was wrong with this thread

http://www.daniweb.com/forums/thread114556.html

Oh, wait, don't tell me. You were upset that I didn't simply give you the answer, but rather tried to make you think. That must have hurt, man. I can't imagine the pain.

Ungrateful kids these days.

@OP

what was wrong with this thread

http://www.daniweb.com/forums/thread114556.html

Oh, wait, don't tell me. You were upset that I didn't simply give you the answer, but rather tried to make you think. That must have hurt, man. I can't imagine the pain.

Ungrateful kids these days.

Now I don't want to start a flame war...*usually followed by a flame war*

but we're brand new at this stuff. We're already confused and not getting it-thus we come to a forum of people with more experience than we for assistance. We've already read a book or had the teacher show us something and it just isn't gelling. Your response was pretty much the same as whats in the book.

Sometimes it takes someone leading you to a place by the nose and showing you what they are talking about. But please don't let me sound ungrateful. I greatly appreciate it when I can get the assistance of someone else. Just sometimes it takes a direct example.

And I understand that you and dozens of other people taught themselves *insert language here* in less than a week or in some light reading. Like many things on the web responses like that don't help the situation at all and merely show an air of condescension and attempted superiority.

Thank you to the people that did post several helpful suggestions. They were very useful in advancing to the next step of this project.

Now I don't want to start a flame war...*usually followed by a flame war*

but we're brand new at this stuff. We're already confused and not getting it-thus we come to a forum of people with more experience than we for assistance. We've already read a book or had the teacher show us something and it just isn't gelling. Your response was pretty much the same as whats in the book.

Sometimes it takes someone leading you to a place by the nose and showing you what they are talking about. But please don't let me sound ungrateful. I greatly appreciate it when I can get the assistance of someone else. Just sometimes it takes a direct example.

And I understand that you and dozens of other people taught themselves *insert language here* in less than a week or in some light reading. Like many things on the web responses like that don't help the situation at all and merely show an air of condescension and attempted superiority.

Thank you to the people that did post several helpful suggestions. They were very useful in advancing to the next step of this project.

Did you actually read the thread pointed to there?

Do you know how much he would have learned had I simply posted the correct version of that line of code? Nothing.

Do you know how much he would have learned had he actually thought and then corrected the problem himself using the very detailed descriptions he was given? That would never have been a problem again.

Now you tell me, which one is better. That "leading by nose" is exactly what I did. Giving out the code is not "leading by the nose", it is pushing aside saying, oh you'll never get it anyway, so let me do it myself. And he learns as much as you think he might with that.

And my post was not to you OP means Original Poster.

Now, your project has gone to the next step, where, presumably, you need to do even more complicated things, predicated on what was presented in this lesson. Well, since you didn't actually learn anything in this lesson, don't you think the next lesson is going to be that much harder?

Edit: And, BTW, if you don't want to "start a flame war", than why did you? That post didn't even concern you, and you could have simply left it alone.

It actually sort of did concern me since I had the same problem and I am in the same boat. I understand that you want to try to teach folks so that they learn themselves. That is noble.

So I'll just end with thankyou for your assistance. Those of us that are not in the know appreciate it when those that have the knowledge are willing to assist in anyway that they can.

BTW, read the thread referenced. The last post in that thread contained some pointed info and questions. If the OP had read that info, then answered the questions, the problem, and it's solution would have become painfully obvious. Seemingly though, the assignment wasn't important enough for the OP to show any effort.

It actually sort of did concern me since I had the same problem and I am in the same boat. I understand that you want to try to teach folks so that they learn themselves. That is noble.

So I'll just end with thankyou for your assistance. Those of us that are not in the know appreciate it when those that have the knowledge are willing to assist in anyway that they can.

The assistance is offered with the stipulation that the poster is making an effort to understand the problem and learn. In the other post that masijade is referring to, there is no effort discernible. It was just a "fix it for me" attitude and when the exact solution was not handed out the poster created a new thread to ask the same question, rather than working through the explicit hints that were given or asking questions to clarify points not understood.

I agree with you guys(Ezzaral, masijade). I have seen many threads here where people just post the code, the line the error is and the message the compiler gives. But the compiler explicitly says what EXACTLY is the problem. It says the line and explains the problem and sometimes says what it needs to be done to fix it. Don't they know how to read? In most cases the answer to those threads would be repeating the compiler's message.
Nowadays there are IDE's that show where the error is, with messages before even compiling (NetBeans) AND with code completion. This is so much easier than my time where I had to write FORTRAN code using UNIX vi editor and compile it at UNIX. Today kids don't want to put any real effort.

import java.io.*;
public class date
{
public static void main()throws IOException
{
int d,m,y,days=0,leap=0,F;
InputSteamReader IR=new InputSteamReader(System.in);
BufferedReader br = new BufferedReader(IR);
System.out.print("Enter Day Number");
d=Integer.parseInt(br.readLine());
System.out.print("Enter the Month");
m=Integer.parseInt(br.readLine());
System.out.Print("Enter the year");
y=Integer.parseInt(br.readLine());
y=y-1990;

if((y%4==0)||((y%400==0)&&(y%100)==0))
{
leap=1;
F=m==1?0:2;
days=(y*365)+(y/4);
m=m-1;

if(m==1||m==3||m==5||m==7||m==8||m==10)
{
days=days+(((m/2)+1)*31)+(((m-1/2)*30)-F;
}
if(m==2||m==4||m==6||m==9||m==11)
{
days=days+((((m-1)/2)+1)*31)+((m/2)*30)-F;
}
days=m!=1?days+leap+d:days+d;
if(days%7==0)
{
System.out.println("Sunday belong to this date");
}
if(days%7==1)
{
System.out.println("Monday belong to this date");
}
if(days%7==2)
{
System.out.println("Tuesday belong to this date");
}
if(days%7==3)
{
System.out.println("Wednesday belong to this date");
}
if(days%7==4)
{
System.out.println("Thursday belong to this date");
}
if(days%7==5)
{
System.out.println("Friday belong to this date");
}
if(days%7==6)
{
System.out.println("Saturday belong to this date");
}
}
}


it says expected at line 26..help sooon!please!!

import java.io.*;
public class date
{
public static void main()throws IOException
{
int d,m,y,days=0,leap=0,F;
InputSteamReader IR=new InputSteamReader(System.in);
BufferedReader br = new BufferedReader(IR);
System.out.print("Enter Day Number");
d=Integer.parseInt(br.readLine());
System.out.print("Enter the Month");
m=Integer.parseInt(br.readLine());
System.out.Print("Enter the year");
y=Integer.parseInt(br.readLine());
y=y-1990;

if((y%4==0)||((y%400==0)&&(y%100)==0))
{
leap=1;
F=m==1?0:2;
days=(y*365)+(y/4);
m=m-1;

if(m==1||m==3||m==5||m==7||m==8||m==10)
{
days=days+(((m/2)+1)*31)+(((m-1/2)*30)-F;
}
if(m==2||m==4||m==6||m==9||m==11)
{
days=days+((((m-1)/2)+1)*31)+((m/2)*30)-F;
}
days=m!=1?days+leap+d:days+d;
if(days%7==0)
{
System.out.println("Sunday belong to this date");
}
if(days%7==1)
{
System.out.println("Monday belong to this date");
}
if(days%7==2)
{
System.out.println("Tuesday belong to this date");
}
if(days%7==3)
{
System.out.println("Wednesday belong to this date");
}
if(days%7==4)
{
System.out.println("Thursday belong to this date");
}
if(days%7==5)
{
System.out.println("Friday belong to this date");
}
if(days%7==6)
{
System.out.println("Saturday belong to this date");
}
}
}


it says expected at line 26..help sooon!please!!

Then go at line 26 and do what the error says. It expects an ')'. In English it means that it misses an ')'.
Or do you expect us to count 26 lines. You didn't even bother to highlight where that line is at your unformatted code.

I didn't even have to count lines - I just looked for the line with the ridiculous number of parentheses, and there's the problem.

udscrick - For each '(' you need an ')'. Work your way out from the center of the expression - the first thing that's evaluated - and you'll see the problem pretty easily.

And no, I won't show you how to fix it, because you need to practice fixing this sort of thing. It's only obvious to me because I've made this mistake a number of times (typos happen to everyone) and so I've had to track this sort of error down a number of times. You'll only be able to spot it in the future if you track it down for yourself.

/**
 * Class Card which holds the card's suit and value as 2 char attributes.
 * Contains many methods for the use of the game.
 * 
 * @author (Lee Norman) 
 * @version (July 2010)
 */
public class Card
{
    private char suit;    // The suit of the card (C,D,H,S)
    private char value;    // The value of the card (A,2,3...10,J,Q,K)
    private String SuitName; // The suit's name(eg,"ace")
    /**
     * Constructor for objects of class Card
     * Creates a Card object with the parameter values as attribute values
     */
      Card(char suit, char value)
    {
         this.suit = suit;
         this.value = value;
         
         if (suit != 'C','D','H','S')
         {
             System.out.print("This is not a valid Suit");
            }
    }

I am getting an ')' expected error and I cannot see where this is needed.
This code is java in BlueJ and doesnt offer any more help on the error.
The error highlighted line #23.
Help/advice would be appreciated, cheers.

/**
 * Class Card which holds the card's suit and value as 2 char attributes.
 * Contains many methods for the use of the game.
 * 
 * @author (Lee Norman) 
 * @version (July 2010)
 */
public class Card
{
    private char suit;    // The suit of the card (C,D,H,S)
    private char value;    // The value of the card (A,2,3...10,J,Q,K)
    private String SuitName; // The suit's name(eg,"ace")
    /**
     * Constructor for objects of class Card
     * Creates a Card object with the parameter values as attribute values
     */
      Card(char suit, char value)
    {
         this.suit = suit;
         this.value = value;
         
         if (suit != 'C','D','H','S')
         {
             System.out.print("This is not a valid Suit");
            }
    }

I am getting an ')' expected error and I cannot see where this is needed.
This code is java in BlueJ and doesnt offer any more help on the error.
The error highlighted line #23.
Help/advice would be appreciated, cheers.

You need something like this:

if ( (suit!='C') && (suit!='D') && (suit!='H') && (suit!='S') )
         {
             System.out.print("This is not a valid Suit");
            }

The line 23 should be replaced by

if ((suit !='C') || (suit !='D') || (suit !='H') || (suit !='S'))

If your intention is logical OR.
Probably, your intention is logical AND as javaAddict indicated(?).

Thanks for the replies.
Logical AND did work, however I would imagine the logic of OR would work.. I'm curious and will come back to it later on :)

(1) if ((suit !='C') || (suit !='D') || (suit !='H') || (suit !='S')) means that suit can be any character.
and
(2) if ((suit !='C') && (suit !='D') && (suit !='H') && (suit !='S')) implies that
suit can be any character other than 'C' or 'D' or 'H' or 'S'

In English, "or" is what you want - if it's not, fish or flesh or fowl, then it must be tofu. But we're not speaking English here, we're evaluating booleans.

if ((suit !='C') || (suit !='D') || (suit !='H') || (suit !='S'))

evaluates as true if any of the sub-expressions are true. If suit =='C', this would be (false)||(true)||(true)||(true), which is true.

on the other hand,

if ((suit !='C') && (suit !='D') && (suit !='H') && (suit !='S'))

evaluates to true if all of the subexpressions are true. If suit =='C', then it's
(false)&&(true)&&(true)&&(true), which is false.

In fact, with lazy-and evaluation (required by the JLS), the expressions after the first false expression are not even evaluated, since we know the result of the total expression already. (similarly, the or expression will evaluate until it gets a true, and then return true)

(1) if ((suit !='C') || (suit !='D') || (suit !='H') || (suit !='S')) means that suit can be any character.
and
(2) if ((suit !='C') && (suit !='D') && (suit !='H') && (suit !='S')) implies that
suit can be any character other than 'C' or 'D' or 'H' or 'S'

Thanks,
Using the && expression works fine :) I get the error message if any other character other than 'C','D','H','S' are used.

Sidetracking here but when I do use a invalid suit such as 'V', the error message appears but an instance is still created. When I run my method getSuit it returns "Null"(which is fine), however my question is; is there a way to stop an instance of the class being created as the message just alerts me it's not a suit but I need it to stop a Caard instance being created

You could throw an IllegalArgumentException in the constructor if the suit is not valid.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.