Results 1 to 5 of 5
  1. #1
    shazakala is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default this post is deleted

    As I dont know how to delete this post I am editing it to show nothing as it nearly lost me my assignment mark posting this information.
    Last edited by shazakala; 04-27-2011 at 01:29 AM. Reason: uni issues.

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    First you should put your code in proper fomatting

    There are basic java errors, char,string, method return type and method signature are not proper

    Check the below code
    Java Code:
    public class Ex5Program {
    
    // start() method has already been written for you - DO NOT change other than removing the //'s when you
    // are ready to test the method.
    
    	public void start() {
    		String name = getNameFromUser();
    		String initialOfFirstName = getInitial(name);
    		String surname = extractSurname(name);
    		printGreeting(initialOfFirstName, surname);
    	}
    
    	private String getNameFromUser() {
    		System.out.println("Enter your name: ");
    		String nameOf = Keyboard.readInput();
    		return nameOf;
    	}
    	private String getInitial(String name) {
    		String firstLetter = name.substring(0,1);
    		return firstLetter;
    	}
    	private String extractSurname(String name) {
    		int sur = name.indexOf(' ');
    		String surAnd = name.substring(sur + 1);
    		return surAnd;
    	}
    	private String printGreeting(String initialOfFirstName, String surname) {
    		System.out.println ("HI " + initialOfFirstName + ". " + surname);
    	}
    }
    sanjeev,संजीव

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    A lot of these errors stem from mismatched types. If it returns a String, you cannot set a char variable to the return of the method.

    For instance, char initialOfFirstName = getInitial(name);

    getInitial has the following method declaration
    Java Code:
    private String getInitial(String name);
    therefore it returns a character, not a String, how about trying to change it so it returns a character? Or change to
    Java Code:
    String initialOfFirstName = getInitial(name);
    You will probably have some other errors but lets fix these first.

  4. #4
    shazakala is offline Member
    Join Date
    Mar 2011
    Posts
    19
    Rep Power
    0

    Default

    Wow you guys are pro, I think i'll stick around this thread, thanks for all the help, program is all fixed except that its complaining on the last close pin as i think it might need to return the statement found back to the top for it to be said -.- I'm sure I will figure it out.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

Similar Threads

  1. some basic advice on using methods please
    By sonny in forum New To Java
    Replies: 2
    Last Post: 03-03-2010, 01:38 AM
  2. THIS PROGRAM IS DRIVING ME CRAZY!!! help fixing it
    By syntrax in forum New To Java
    Replies: 2
    Last Post: 12-18-2009, 05:27 AM
  3. 3 basic program
    By jasskulainen in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 02:39 PM
  4. [SOLVED] Need a program for learning purposes.
    By Zebra in forum New To Java
    Replies: 19
    Last Post: 05-03-2008, 04:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •