First and Last Name Pig Latin

Using Strings, Substrings, and UpperCase

Page 1 of 1

6 Replies - 12753 Views - Last Post: 27 January 2010 - 01:43 PM Rate Topic: -----

#1 pscmh7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 09

First and Last Name Pig Latin

Post icon  Posted 26 January 2010 - 08:34 PM

I am trying to complete this assignment, with only about 10 days of an introduction to Java. I only know the very basics of Java and am working hand in hand with my book to try and solve this assignment:

Write a program that starts with the string variable first set to your first name and the string variable last set to your last name. Both names should be all lowercase. Your program should then create a new string that contains your full name in pig latin with the first letter capitalized for the first and last name. Use only the pig latin rule of moving the first letter to the end of the word and adding “ay”. Output the pig latin name to the screen. Use the substring and toUpperCase methods to construct the new name. For example, given
first= “walt”;
last=”savitch”;
the program should create a new string with the text “Altway Avitchsay” and print it.

I know I am missing something here to pull it all together. The problem is, I do not understand enough to know what is missing and how to further investigate how to fix it. I will gladly take any help, no matter how minimal it may be--I just need help getting on track.


import java.util.Scanner;

public class PigLatin
{
	public static void main(String[] args)
{
	System.out.println("Bob Marley in Pig Latin is...");
	String first = "bob";
	String last = "marley";

	first.substring(1, 2);

	last.substring(1, 5);


	String fullname = first + "bay" + last + "may";
	fullname.toUpperCase(0);
	fullname.toUpperCase(5);

	System.out.println(fullname);
	}
	}



Is This A Good Question/Topic? 0
  • +

Replies To: First and Last Name Pig Latin

#2 333OnlyHalfEvil   User is offline

  • D.I.C Addict

Reputation: 24
  • View blog
  • Posts: 674
  • Joined: 20-March 09

Re: First and Last Name Pig Latin

Posted 26 January 2010 - 08:40 PM

You need to have a variable that the two substrings are being set to.
String a = first.substring(1,2);
String b = last.substring(1,5);


Then you do the fullname conversion to piglatin.
String fullname = a + "bay" + last + "may";


Was This Post Helpful? 1
  • +
  • -

#3 pscmh7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 09

Re: First and Last Name Pig Latin

Posted 26 January 2010 - 08:58 PM

Thank you for your help. So I fixed that error and tried compiling it again, and I had errors regarding the UpperCase. I tried doing a similar String "variable" = a.toUpperCase () for both uppercases, so then I tried Uppercasing the final "full name" product. The same error keeps telling me that the "." between the string name and UpperCase is not recognized. Is it possible to UpperCase more than one position at a time? i.e. first.toUpperCase(1,4)?

import java.util.Scanner;

public class PigLatin
{
	public static void main(String[] args)
{
	System.out.println("Bob Marley in Pig Latin is...");
	String first = "bob";
	String last = "marley";


	String a = first.substring(1, 2);

	String b = last.substring(1, 5);



	String fullname = a + "bay" + b + "may";
	fullname.toUpperCase(0);
	fullname.toUpperCase(5);


	System.out.println(fullname);
	}


Was This Post Helpful? 0
  • +
  • -

#4 333OnlyHalfEvil   User is offline

  • D.I.C Addict

Reputation: 24
  • View blog
  • Posts: 674
  • Joined: 20-March 09

Re: First and Last Name Pig Latin

Posted 26 January 2010 - 10:28 PM

Are you getting an error or is it just not working the way you want it to? If it's an error can you post the actual error message you're getting?
Was This Post Helpful? 1
  • +
  • -

#5 pscmh7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 09

Re: First and Last Name Pig Latin

Posted 27 January 2010 - 12:19 PM

I am trying to get only the 1st letter of my first name and only the first letter of my last named to UpperCase. I've tried the book and internet searching to see how to convert only select characters of the string to UpperCase. Is it possible to convert only a few characters of the string or do I have to create another variable? Here is what I have so far, I've been playing around with the program trying to alter the uppercase and now I'm at having both strings uppercase.
import java.util.Scanner;

public class PigLatin
{
	public static void main(String[] args)
{
	System.out.println("Michelle Hothman in Pig Latin is...");
	String first = "michelle";
	String last = "hothman";


	String a = first.substring(1, 7);

	String b = last.substring(1, 6);
	a = a.toUpperCase();
	b = b.toUpperCase();


	String fullname = a + "may  " + b + "hay";
;

	System.out.println(fullname);
	}
	}


Was This Post Helpful? 0
  • +
  • -

#6 Moogoo   User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 82
  • Joined: 06-January 10

Re: First and Last Name Pig Latin

Posted 27 January 2010 - 01:28 PM

I noticed that your program is importing java.util.scanner. Does your assignment require only one type of output, or do you need to be able to take user input and convert it to pig latin?
Was This Post Helpful? 0
  • +
  • -

#7 pscmh7   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-February 09

Re: First and Last Name Pig Latin

Posted 27 January 2010 - 01:43 PM

View PostMoogoo, on 27 Jan, 2010 - 12:28 PM, said:

I noticed that your program is importing java.util.scanner. Does your assignment require only one type of output, or do you need to be able to take user input and convert it to pig latin?



The assignment does ask for one type of output, no input is taken from keyboard scanner and coverted.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1