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 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,...
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.
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...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns...
Python program. Write a function called cleanLowerWord that receives a string as a parameter and returns a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this, you can start by copying the following functions discussed in class into your file: # Checks if ch is...
Write a Python program which takes a set of positive numbers from the input and returns...
Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
In PYTHON: Write a function that receives a sentence and returns the last word of that...
In PYTHON: Write a function that receives a sentence and returns the last word of that sentence. You may assume that there is exactly one space between every two words, and that there are no other spaces at the sentence. To make the problem simpler, you may assume that the sentence contains no hyphens, and you may return the word together with punctuation at its end.
Write a Java program called RevenueAdvanced to calculate the revenue from a sale based on the...
Write a Java program called RevenueAdvanced to calculate the revenue from a sale based on the unit price and quantity of a product input by the user. (use if and if-else statements) • The discount rate is o 0% for the quantity purchased between 1 and 49 units. o 10% for the quantity purchased between 50 and 99 units. o 15% for the quantity purchased between 100 and 149 units. o 25% for the quantity purchased greater than or equal150...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT