In: Computer Science
Write a program called Teen that takes a sentence and returns a new sentence based on how a teenager might say that. The method that creates the new string should be called teenTalk and should have the signature shown in the starter code.
The way to do that is to put the word "like" in between each of the words in the original sentence.
For example, teenTalk("That is so funny!") would return "That like is like so like funny!".
Sample output:
Sonequa Martin-Green is in grade 10 and wants to send this text: Enter the text message being sent: Hello world how are you doing? The teen talk text would be: Hello like world like how like are like you like doing?
Coding Portion:
public class TeenTester
{
public static void main(String[] args)
{
// Create a new Teen object and print it out; see the Teen class
file
// to see how the constructor and toString method work.
Teen myFriend = new Teen("Sonequa", "Martin-Green", 10,
true);
System.out.println(myFriend.toString());
// Ask the user to input a text message
//Call teenTalk method to translate the message to teen talk
}
}
Different Class:
public class Teen
{
private String firstName;
private String lastName;
private int grade;
private Boolean textMessages;
// Constructor to make a teen with a first and last
name, grade in school,
// and whether they text message others and need to write texts to
others.
// This defines the state of the teen.
public Teen(String theFirstName, String theLastName, int theGrade,
Boolean theTextMessages)
{
firstName = theFirstName;
lastName = theLastName;
grade = theGrade;
textMessages = theTextMessages;
}
// toString method to print out the state of teen object
public String toString()
{
return firstName + " " + lastName + " is in grade " + grade + " and
wants to send this text:";
}
// Create this method so that it changes the text message
// and places the word "like" in place of each space
// in the message.
public String teenTalk(String text)
{
}
}
package mis1;
import java.util.Scanner;
public class TeenTester
{
public static void main(String[] args)
{
// Teen t=new Teen("baby","bear",2,true);// Create a new Teen object and print it out; see the Teen class file
// to see how the constructor and toString method work.
Teen myFriend = new Teen("Sonequa", "Martin-Green", 10, true);
System.out.println(myFriend.toString());
Scanner sc=new Scanner(System.in);// Ask the user to input a text message
String talk=sc.nextLine();
String babyTalk=myFriend.teenTalk(talk); //Call teenTalk method to translate the message to teen talk
System.out.println(babyTalk);
}
}
class Teen
{
private String firstName;
private String lastName;
private int grade;
private Boolean textMessages;
// Constructor to make a teen with a first and last name, grade in school,
// and whether they text message others and need to write texts to others.
// This defines the state of the teen.
public Teen(String theFirstName, String theLastName, int theGrade, Boolean theTextMessages)
{
firstName = theFirstName;
lastName = theLastName;
grade = theGrade;
textMessages = theTextMessages;
}
// toString method to print out the state of teen object
public String toString()
{
return firstName + " " + lastName + " is in grade " + grade + " and wants to send this text:";
}
// Create this method so that it changes the text message
// and places the word "like" in place of each space
// in the message.
public String teenTalk(String text)
{
String babyTalk[]=text.split(" "); //split the words in input
String babyTalkString ="";
for(int i=0;i<babyTalk.length;i++){ //for each words
if(i!=babyTalk.length-1){ //add like after it
babyTalkString+=babyTalk[i]+" like ";
}
else{
babyTalkString+=babyTalk[i]; //but not after last words
}
}
return babyTalkString;//return babytalk string
}
}
output
Sonequa Martin-Green is in grade 10 and wants to send this text:
Hello world how are you doing?
Hello like world like how like are like you like doing?