Complete the generateFormalName method so that… you return the formal name (Mr. or Ms. + last name) given a full name and gender (Strings) as parameters.
--You can assume a valid name & gender (any case allowed) is passed in. Example 1: ("Bob Smith", "MaLE") passed in should generate "Mr. Smith" Example 2: ("Maggie May", "feMALE") passed in should generate "Ms. May"
Tip 1: You are given a String formalName initialized to the empty String -- you will want to concatenate other Strings onto this to produce the full formalName.
Tip 2: Write your algorithm in English first.
Tip 3: Think of all of the methods at your disposal and which could be helpful.
Given Code:
public class StringPractice {
public String generateFormalName(String fullName,
String gender)
{
String formalName = "";
//Insert your code here:
return formalName;
}
}
import java.util.*;
import java.lang.*;
import java.io.*;
public class StringPractice
{
public static void main (String[] args) throws
java.lang.Exception
{
System.out.println(generateFormalName("Maggie May",
"feMALE"));
}
public static String generateFormalName(String
fullName, String gender)
{
String formalName = "";
String[] arrOfStr = fullName.split("\\s");
if(gender.toLowerCase().equals("female"))
{
formalName="Ms. "+arrOfStr[1];
}
else if(gender.toLowerCase().equals("male"))
{
formalName="Mr. "+arrOfStr[1];
}
return formalName;
}
}
Complete the generateFormalName method so that… you return the formal name (Mr. or Ms. + last...
These are the instructions for a java file. We have not learned
array of string or anything that complex. I am trying to solve this
possibly using the IndexOf method.
13.4 Assignment 4: Formal Name Generator Complete the generateFormalName method so that... you return the formal name (Mr. or Ms. + last name) given a full name and gender (Strings) as parameters. --You can assume a valid name & gender (any case allowed) is passed in. Example 1: ("Bob Smith",...
Please run the program and show the result with screenshots after. Thank you (Java Eclipse) Customer Data: Area Codes Assume you work for a company that tracks customer information, including name, gender and phone numbers Your company has a file called customers.txt which contains the following information: Jiming Wu F 4082123458 James Brown M 8315678432 Leanna Perez F 4087654433 Xing Li M 8313214555 Stacey Cahill O 8312123333 Mohammed Abbas M 4083134444 Kumari Chakrabarti F 4086667777 Shakil Smith M 4082123333 Jung...
JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...
Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty string, it should do nothing; but otherwise it should set the appropriate field. For setMobile: if the method is passed a valid mobile phone number, it should set the appropriate field; otherwise it should do nothing. A string is a valid mobile phone number if every character in it is a digit from 0 to 9. Hints: To convert a string so you can...
JAVA Can you make this return the first letter of first and last name capitalized? import java.io.File; import java.io.IOException; import java.util.*; public class M1 { public static void main(String[] args) { //scanner input from user Scanner scanner = new Scanner(System.in); // System.out.print("Please enter your full name: "); String fullname = scanner.nextLine(); //creating a for loop to call first and last name separately int i,k=0; String first="",last=""; for(i=0;i<fullname.length();i++) { char j=fullname.charAt(i); if(j==' ') { k=i; break; } first=first+j;...
WHERE in this code should you put the main method so that the code will compile WITHOUT changing anything else in the code? Simply adding the main method only? public class Account { private String name; private double balance; public Account(String name, double balance) { this.name = name; if (balance > 0.0) this.balance = balance; } public void deposit(double depositAmount) { if (depositAmount > 0.0) balance += depositAmount; } public double getBalance() { return balance; } public String...
LAB PROMPT: Lab 06 For this lab you are going to practice writing method signatures, implementing if statements, and improve your skills with for loops. The methods you will be writing have nothing to do with each other but allow you to use the skills you have gained so far to solve a series of small problems. Power For this method you will practice using methods from the Math class. The first step you must take is to write the...
Write a method called printReverse() that
takes a string and uses recursion to print the contents of the
string in reverse order. The string itself should
not be reversed; it must be left in its
original form.
The method has the following header:
void printReverse(String s, int i)
where s is a reference to the string, and i is an integer
parameter that you may use as you see fit. You do not need
to code up this method as...
C++ with Pseudocode in the beginning This assignment will require you to write a program that will create an array of 10 string objects. The array will be initialized with the strings which contain the person’s name and phone number in one string. The following is an example of test data: “Renee Javens, 678-1223”, “Joe Looney, 586-0097”, “Geri Palmer, 223-8787”, “Lynn Presnell, 887-1212”, “Bill Wolfe, 223-8878”, “Sam Wiggins, 486-0998”, “Bob Kain, 586-8712”, “Tim Haynes, 586-7676”, “John Johnson, 223-9037”, “Jean James,...
Java A bigram is a pair of adjacent words in a sequence. Bigrams overlap so that in the sequence "a b. c d", the bigrams are ("a", "b."), ("b.", "c"), ("c", "d"). You will write a simple parser which builds a bigram model based on input text and will allow checking sentences and generating sequences. To do so, you should take advantage of Java’s collection classes including Maps. Create a class called Bigram. The class will have a constructor which...