Thread: Java Code Question
-
July 5th, 2011, 12:39 PM #1Junior Member
- Join Date
- Jul 2011
- Posts
- 1
Java Code Question
im trying to write a code to create new names based on two names the user inputs. i keep getting errors and i can figure out what is going on. here is the code and the errors. any help would be great.
********************
import java.util.*;
public class GeneratingNames{
public static void main (String[] args){
System.out.println("Lab 4 written by David Strauss");
Scanner CONSOLE = new Scanner(System.in);
for (int i =1; i <=3; i++){
String name1 = CONSOLE.next();
String name2 = CONSOLE.next();
String newname1 = genName1(name1, name2);
String newname2 = genName2(name1, name2);
System.out.println(name1 + "\t" + newname1);
System.out.println(name1 + "\t" + newname2);
}
}
public String genName1(String name1,String name2){
int length1 = name1.length();
int length2 = name2.lenght();
int half1 = length1/2;
int half2 = length2/2;
String firsthalf1 = name1.substring(0, half1);
String secondhalf2 = name2.substring(half2, length2);
String newname = firsthalf1 + secondhalf2;
return newname;
}
public String genName1(String name1, String name2){
int length1 = name1.length();
int length2 = name2.lenght();
int half1 = length1/2;
int half2 = length2/2;
String secondhalf1 = name1.substring(half1, length1);
String firsthalf2 = name2.substring(0, half2);
String newname = firsthalf2 + secondhalf1;
return newname;
}
}
*********************
5 errors found:
File: Z:\working\cs1063\lab4\GeneratingNames.java [line: 14]
Error: Z:\working\cs1063\lab4\GeneratingNames.java:14: non-static method genName1(java.lang.String,java.lang.String) cannot be referenced from a static context
File: Z:\working\cs1063\lab4\GeneratingNames.java [line: 15]
Error: Z:\working\cs1063\lab4\GeneratingNames.java:15: cannot find symbol
symbol : method genName2(java.lang.String,java.lang.String)
location: class GeneratingNames
File: Z:\working\cs1063\lab4\GeneratingNames.java [line: 24]
Error: Z:\working\cs1063\lab4\GeneratingNames.java:24: cannot find symbol
symbol : method lenght()
location: class java.lang.String
File: Z:\working\cs1063\lab4\GeneratingNames.java [line: 38]
Error: Z:\working\cs1063\lab4\GeneratingNames.java:38: genName1(java.lang.String,java.lang.String) is already defined in GeneratingNames
File: Z:\working\cs1063\lab4\GeneratingNames.java [line: 40]
Error: Z:\working\cs1063\lab4\GeneratingNames.java:40: cannot find symbol
symbol : method lenght()
location: class java.lang.String
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Java Code Question
By thehillsd in forum Applications and Operating SystemsReplies: 0Last Post: June 9th, 2010, 08:38 AM -
Java Code Help
By abalasuriya in forum Webmastering and ProgrammingReplies: 0Last Post: November 1st, 2009, 09:39 PM -
java code question...
By lostgoat in forum Webmastering and ProgrammingReplies: 0Last Post: July 13th, 2009, 02:43 PM -
Can someone help me with this Java Code?
By quantumlight in forum Webmastering and ProgrammingReplies: 4Last Post: November 9th, 2008, 04:02 PM -
Need help with some Java Code :P
By Soheils91 in forum General Tech DiscussionReplies: 2Last Post: October 20th, 2004, 07:57 PM



LinkBack URL
About LinkBacks



Reply With Quote

I think Chuckie should go to jail for slinging such obvious BS, lol . . .
Voter Suppression is Alive and...