Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java programming

Name: Anonymous 2006-09-21 10:55

Hi y'all,

I'm new to Java and we just started on the else/if statements. I'm not good when it comes to programming, and this is my first programming language.

This is the actual homework problem:

Create a program with a dialog box that will use letters a, b or c in the code to recognize the first letter of a word and then will output a statement.

For example if the dialog were to ask, "Please enter your first name" and Andrew was entered.

The program could output, "Apples begin with your first letter, Andrew."
A word, such as Apples would be assigned for each letter a, b and c.
___________________________________________________________________
___________________________________________________________________

And here is my code:

import java.util.Scanner;

public class namesAndFruit
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);

char a = string.charAt(0);
char b = string.charAt(0);
char c = string.charAt(0);

String a = apple;
String b = banana;
String c = cantalope;

System.out.print("Please enter your first name: ");
String firstName = input.next();
System.out.println("Your name is " + firstName);

if(Character.isLetter(a))
System.out.println(+a "begins with your first letter, " + firstName);

if(Character.isLetter(b))
System.out.println(+b "begins with your first letter, " + firstName);

if(Character.isLetter(c))
System.out.println(+c "begins with your first letter, " + firstName);

}
}
____________________________________________________________________
____________________________________________________________________

And here is the error messages when I compiled them:


D:..is222..names..>javac *.java

namesAndFruit.java:23: ')' expected
System.out.println(+a "begins with your first letter, " + firstName);
^
namesAndFruit.java:26: ')' expected
System.out.println(+b "begins with your first letter, " + firstName);
^
namesAndFruit.java:29: ')' expected
System.out.println(+c "begins with your first letter, " + firstName);
^
3 errors

___________________________________________________________
___________________________________________________________

I wish I can post my code correctly here with the line numbers, but I don't know how. From what I've seen in this group, you guys/gals are really smart and insightful.

Thank you!!!
Josephine

Name: Anonymous 2006-09-21 10:57

PS: it's a copy pasta from myspace... just laugh at the dislexic programming...

Name: Anonymous 2006-09-21 11:29

Why oh why do they start the kids on Java? I had to help a freind of mine through a class with classes just as wierd.  Wouldn't it make more sense to teach OOP After you learn the basics??

Name: Anonymous 2006-09-21 12:22

>>3
>Why oh why do they start the kids on Java?

Because it's one of the cleanest languages available.

Name: Anonymous 2006-09-21 17:39 (sage)

>>4
*cough*DUMBASS*cough*

Name: Anonymous 2006-09-21 20:02

>>3
Yes, but if they are stupid enough to teach Java at all, would you expect they'd realize this?

>>4
>>5

Name: Anonymous 2006-09-21 22:33

public class namesAndFruit
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);

char a = a;
char b = b;
char c = c;

String a = "apple";
String b = "banana";
String c = "cantalope";

System.out.print("Please enter your first name: ");
String firstName = input.next();
System.out.println("Your name is " + firstName);

if(firstName.charAt(0) == a)
System.out.println(a + "begins with your first letter, " + firstName);

if(firstName.charAt(0) == b)
System.out.println(b + "begins with your first letter, " + firstName);

if(firstName.charAt(0) == c)
System.out.println(c + "begins with your first letter, " + firstName);

}
}

that should work?

Name: Anonymous 2006-09-21 22:37

Actually here you go..  it works...

import java.util.Scanner;

public class namesAndFruit
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);

char a = 'a';
char b = 'b';
char c = 'c';

String apple = "apple";
String banana = "banana";
String cantalope = "cantalope";

System.out.print("Please enter your first name: ");
String firstName = input.next();
System.out.println("Your name is " + firstName);

if(firstName.charAt(0) == a)
System.out.println(apple + "begins with your first letter, " + firstName);

if(firstName.charAt(0) == b)
System.out.println(banana + "begins with your first letter, " + firstName);

if(firstName.charAt(0) == c)
System.out.println(cantalope + "begins with your first letter, " + firstName);

}
}

Name: Anonymous 2006-09-22 6:02

>>4
That's the mistake they always make, while it produces clean an organized programing that makes a lot of sence for trained programers, OO IS an advanced concept for newbies an object can be a natural thing, but the Java babbling code is not!

Name: Anonymous 2006-09-22 8:39

>>9
That's the mistake they always make, while it produces clean an organized programing that makes a lot of sence
Java does not produce "clean an organized programing that makes a lot of sence".

Name: Anonymous 2006-09-22 9:32

>>5
cough*you fail*cough

>>9
It's up to the teacher to explain how it's used.

Name: Anonymous 2006-11-14 21:20

ava

Name: Anonymous 2009-01-14 13:41

lol sepples

Name: Anonymous 2011-05-26 11:10

C# > Java

Name: Anonymous 2011-05-26 11:21

Lisp > *

Name: Anonymous 2011-05-26 11:30

>>8
if(firstName.charAt(0) == a)
System.out.println(apple + "begins with your first letter, " + firstName);

if(firstName.charAt(0) == b)
System.out.println(banana + "begins with your first letter, " + firstName);

if(firstName.charAt(0) == c)
System.out.println(cantalope + "begins with your first letter, " + firstName);


switch(firstName.charAt(0))
{
    case 'A':;case 'a': System.out.println(apple + "begins with your first letter, " + firstName); break;
    case 'B':;case 'b': System.out.println(banana + "begins with your first letter, " + firstName); break;
    case 'C':;case 'c': System.out.println(cantalope + "begins with your first letter, " + firstName); break;
    default: break;
}

Name: >>17 2011-05-26 11:34

>>17
System.out.println(cantalope + "begins with your first letter, " + firstName); *

Name: Anonymous 2011-05-26 14:31

>>17
System.out.println((firstName.charAt(0).EqualsIgnoreCase('a'))?apple:(firstName.charAt(0).EqualsIgnoreCase('b'))?banana:(firstName.charAt(0).EqualsIgnoreCase('c'))?cantalope:"lol " + "begins with your first letter, " + firstName);

Name: VIPPER 2011-05-26 14:59

Shitty thread, go away.

Name: Sgt.Kabu廤꣊kiman䫺 2012-05-28 20:07

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List