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

Urgently need help for school program please help

13
Hi to all I'am trying to run this program for my school progect but I keep receiving the same answer when I compile ')' expected. on the highlighted line can anyone help me thanks to all.



/**
* Write a description of class Records here.
*
* @author (Ryan MIfsud)
* @version (version 1)
*/
public class Records
{


public static void main (String Args []){

String Student_Name1;
String Student_surname1;
String Student_ID1;
String Student_group1;
System.out.println ("Enter name ");
int name = Keyboard.readInt();
char grade;

grade = '_';

if ( name > Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle || name < Kurt) System.out.println ("name is not included");
else

if (name >= Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle && name <= Kurt )
grade = 'name included';



System.out.println ( "Enter student's name" );
Student_Name1 = Keyboard.readString();

System.out.println ( "Enter student's surname" );
Student_surname1 = Keyboard.readString();

System.out.println( "Enter student's ID" );
Student_ID1 = Keyboard.readString();

System.out.println( "Enter student's group" );
Student_group1 = Keyboard.readString();

System.out.println ( Student_Name1 + Student_surname1 + Student_ID1 + Student_group1 );

System.out.println ("End by entering -1");
int counter = -1;


}

}
Jul 16 '07 #1
15 1594
blazedaces
284 100+
Hey, from now on please put your code in code tags (look on the right when you post on the box that says "REPLY GUIDELINES". Also, could you post the full error you get when you try to compile. I'm a bit confused as to what exactly it's trying to tell you...

-blazed
Jul 16 '07 #2
r035198x
13,262 8TB
if (name >= Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle && name <= Kurt )
grade = 'name included';


Those two lines will not compile. What are you trying to do there?
Also char variable can only hold chars.
Jul 16 '07 #3
max3
13
I'am trying to creat a program that when I give name ,surname and Id in the list it will give me the name and when it is not in the list it will say name not included thanks for your interest and sorry to Blazedaces about the the codes but I'm still new in this fourm and did't understand exactly how the codes work thank you

When I compile this is what I get ')' expected
Jul 16 '07 #4
blazedaces
284 100+
I'am trying to creat a program that when I give name ,surname and Id in the list it will give me the name and when it is not in the list it will say name not included thanks for your interest and sorry to Blazedaces about the the codes but I'm still new in this fourm and did't understand exactly how the codes work thank you

When I compile this is what I get ')' expected
I don't think you can compare more then one result by separating it by a comma like that. I don't think this is possible: name < firstVariable, secondVariable. I think you need to do name < firstVariable && name < secondVariable.

The compiler may think the comma indicates some end for the if statement and wants you to close the parenthesis or something. Also, as mentioned by r035198x above, are you comparing characters or is name and those variables simply integers or something?

Why are you using < to find out if the name is not included in the list?

-blazed
Jul 16 '07 #5
max3
13
Hi I'm only trying to find a selective name out of the list and regarding using this symbol < I think it's the best in my opinion have you any suggestions? thanks what in your opinion should I do to make this program work.
Jul 16 '07 #6
blazedaces
284 100+
Hi I'm only trying to find a selective name out of the list and regarding using this symbol < I think it's the best in my opinion have you any suggestions? thanks what in your opinion should I do to make this program work.
The "<" symbol compares two numbers and if the first is "less than" the other, it returns true, otherwise it returns false... How does this have anything to do with finding a selective name out of the list?

If you asked a random person "is Jake less then Ronald" they would ask you what you're talking about, which is exactly what the JVM will do.

What I think you should do is go through the entire list one at a time and ask "is Jake the same name as ronald?" no, repeat throughout the entire list. Use the String1.equals(String2) method...

Good luck,
-blazed
Jul 16 '07 #7
r035198x
13,262 8TB
Hi I'm only trying to find a selective name out of the list and regarding using this symbol < I think it's the best in my opinion have you any suggestions? thanks what in your opinion should I do to make this program work.
Have you read a tutorial about how that symbol is used?
Jul 16 '07 #8
max3
13
R035198 the < symbol means less than and I think it is one of the problems I have I try to change as blazedaces said and tell you what happend later .thanks
Jul 16 '07 #9
JosAH
11,448 Expert 8TB
if ( name > Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle || name < Kurt)
Don't just guess what Java's syntax is supposed to be according to what you
wish it to be. Compare it to this: suppose I have my own private understanding
of what a 'fronobulax' is supposed to be. Nobody else would understand me if
I'd ask anyone where to buy fresh fronobulaxes. If you want to program in Java
you have to speak the Java language. When in Rome, do as the Romans do.

kind regards,

Jos
Jul 16 '07 #10
Hi,


I don't know whether this statement which u used is valid or not(if ( name > Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle || name < Kurt) ). But what i suggest is write like this [if (( name > Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle) || (name < Kurt) )] when ever u use this || or && operators.

Hi all let me know if i'm wrong.
Jul 18 '07 #11
JosAH
11,448 Expert 8TB
Hi,


I don't know whether this statement which u used is valid or not(if ( name > Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle || name < Kurt) ). But what i suggest is write like this [if (( name > Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle) || (name < Kurt) )] when ever u use this || or && operators.

Hi all let me know if i'm wrong.
You're wrong ;-)

If those names are comparable using the '<' or '>' operators they need to be
identifiers of primitive numerical type. If they are of type String, those operators
can't be used. The comma operator isn't defined in Java. That 'statement' (mind
the quotes) is completely wrong.

kind regards,

Jos
Jul 18 '07 #12
I think from the discussion i gathered this information:
the names you're comparing against are the “accepted” names for this course, group etc therefore the user is limited to just those and has a “closed” outlook to any other, hence the need for an if statement that compares twice against just that list.
The problem: implement this closet in a list such that when a name is to be in this close group, there is a list to compare against. Instead of doing:
if (name > X1, X2 || name < X3 etc) //this is a list, maybe two lists the comparison on greater than and on less than?
Rather do:
If ( list1.contains(name) || list2.contains(name)) then...”name included”.
else ....”name not included” //somewhat simpler and less code.

i wonder what your keyboard class is? Can't find any Keyboard class in the jdk 6 documentation though i believe it refers to user input. Why do you have to readInt this input and then compare against String? No compiler would accept that. Rather read on string and verify on string input since this is name and name should be string, if black is black and never shades of it.
Jul 18 '07 #13
thanks Jos for correcting me
Jul 19 '07 #14
thanks Jos for correcting me

hi,
you have taken name as integer and names are in string,
they r incompatable types.
compare name with the length of strings and also take all the atrings into an array.
I think taht oparator will not compare more than one so better to take all strings into array.
String [] arr = new String[Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle] ;

for(int i=0;i<arr.size();i++)
{
if(name>(arr.get(i)).length()||name<kurt.length())
System.out.println("not included);
else
if (name >=(arr.get(i)).length()&& name <= Kurt.length() )
grade = 'name included'

}
once try this iam not sure
Jul 20 '07 #15
blazedaces
284 100+
hi,
you have taken name as integer and names are in string,
they r incompatable types.
compare name with the length of strings and also take all the atrings into an array.
I think taht oparator will not compare more than one so better to take all strings into array.
String [] arr = new String[Ryan,Robert,Victor,Jim,Sammy,Leo,Glen,Kyle] ;

for(int i=0;i<arr.size();i++)
{
if(name>(arr.get(i)).length()||name<kurt.length())
System.out.println("not included);
else
if (name >=(arr.get(i)).length()&& name <= Kurt.length() )
grade = 'name included'

}
once try this iam not sure
That won't work ... that is, it will compile but not do what is needed.

The lengths of the names in that array are 4, 6, 6, 3, 5, 3, 4, 4. That means ANY string with a length of 3, 4, 5, or 6 will print that the name is included. He's not checking that it's the correct length, he's checking that the name is included in the list...

-blazed
Jul 20 '07 #16

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

Similar topics

3
by: Elezar Simeon Papo | last post by:
Hello All, I have a tab separated input file (data.txt) in text format - the file looks like this SCHOOL DEPART1 DEPART2 DEPART3 Harvard Economics Mathematics Physics...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
22
by: the_grove_man | last post by:
I purchased a book titled "Pro ASP.NET 2.0" to get up to speed on web stuff because I ususally do Windows Form Applications.. But in the first chapters I was reading this week it brought to mind...
1
by: simonalexander | last post by:
I have got a homework task to do and I have started the work but I cannot finish it.Can someone please help me finish the code. The help given is much appreciated. The actual specifications are...
5
by: Lockwood | last post by:
someone check out this program and tell me what im doing wrong please...every time i fix some errors i get even more than before (right now theres 10). note that im a beginner/noob, and that this...
3
by: dreams | last post by:
Hi every one :) would any one help me in this program: I have a base class called "Person" and two derived classes "Student" and "teacher" i have a function in class Student called getStudents...
2
by: max3 | last post by:
Please can someone help me run this program I must be misssing something and it's not working thanks to all. /** * Write a description of class Records here. * * @author (Ryan MIfsud)...
0
by: efix | last post by:
hey there i need help urgently.. neone hu cud help me?? U c i m tryin t figure out how to program a vb .exe to login into a internet account inreal time. i m playin an online game....
8
by: 08butoryr | last post by:
Hey guys I could really use your help with some very basic java programming. I know you programming fundis out there will find this child's play but I'm struggling with it a bit because I'm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.