Question

In: Computer Science

Write a program called Teen that takes a sentence and returns a new sentence based on...

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)
{
  
}
  
}

Solutions

Expert Solution

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?


Related Solutions

C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
write an algorithm function called balance() in javascript that takes in a string and returns a...
write an algorithm function called balance() in javascript that takes in a string and returns a strinf with balanced parantheses only. the string should be able to contain only parantheses, numbers, and letters. include comments of each portion of your code balance(“()()”) should return “()()” balance(“())”) should return “()” balance(“a(b)c”) should return “a(b)c” balance(“a(b)c())”) should return “a(b)c()”
In C++ Write a function called findBestSimScore that takes a genome and a sequence and returns...
In C++ Write a function called findBestSimScore that takes a genome and a sequence and returns the highest similarity score found in the genome as a double. Note: the term genome refers to the string that represents the complete set of genes in an organism, and sequence to refer to some substring or sub-sequence in the genome. Your function MUST be named findBestSimScore Your function should take two parameters in this order: a string parameter for the genome (complete set...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at...
Write the definition of a Point class method called clone that takes NO arguments and returns...
Write the definition of a Point class method called clone that takes NO arguments and returns a new Point whose x and y coordinates are the same as the Point’s coordinates.
JAVA Arrays 4 Write a method called isPalindrome that takes a String as input and returns...
JAVA Arrays 4 Write a method called isPalindrome that takes a String as input and returns true if the String is a palindrome.
C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT