Write a java method called gangstaName ( ) that reads a person's name and converts it into a "gangsta name."
Output (run 1):
Type your name, playa: Peter Griffin
(M)ale or (F)emale? m
Your gangsta name is "P. GRIFFIN Daddy Peter-izzle"
Output (run 2):
Type your name, playa: Marge Simpson
(M)ale or (F)emale? F
Your gangsta name is "M. SIMPSON Goddess Marge-izzle"
import java.util.Scanner;
public class GangstaName {
public static String gangstaName(String name, char gender) {
String[] words = name.split(" ");
String first = words[0], last = words[1];
if(gender == 'F') {
return first.substring(0, 1) + ". " + last.toUpperCase() + " Goddess " + first + "-izzle";
} else {
return first.substring(0, 1) + ". " + last.toUpperCase() + " Daddy " + first + "-izzle";
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Type your name, playa: ");
String name = in.nextLine();
System.out.print("(M)ale or (F)emale? ");
char gender = in.next().charAt(0);
System.out.println("Your gangsta name is \"" + gangstaName(name, gender) + "\"");
in.close();
}
}
Write a java method called gangstaName ( ) that reads a person's name and converts it...
Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline. Example output if the input is Maya Jones Tones, Maya import java . util·Scanner; public class SpaceReplace 4 public static void main (String [1 ares) f( Scanner scnr-new Scanner(System.in); String firstName; String lastName; Your solution goes here */ 10 12
3. Write a Java method (called sumOfSquares) that reads in a sequence of integer numbers using a Scanner object. As each integer is read, the method displays that integer. The method also accumulates the sum of the squares of the integers and displays the sum when all integers are read. The method reads integers until a negative integer is read. The negative integer should not be display or added to the sum of squares. The method will not return a...
java question: Write a program that reads in data from a text file named in.txt. Compute the sum of all the valid integers in the input file. Likewise, compute the sum of all the valid doubles in the input file. Write the former to an output file called int_total.txt, and write the latter to an output file called double_total.txt. B) Write a program that converts the Java source code from the next-line brace style to the end-of-line brace style. For...
In Java: Let's create a method that has parameters. Write a method, called returnHours that returns a string. Make the string from a string representing your name and a number representing the hours you spend sleeping, both are values that you pass in from the main. Create the variables to pass into the method call in main. Call the method and print the return value in main. Run and test it.
Java: Write a static method named longestName that reads a series of names typed by the user and prints the longest name (i.e., the name with the most characters). The method should accept a Scanner object, console and an integer, n as parameters. After prompting and reading in n names, the longest name should be printed as follows: its first letter should be capitalized and all subsequent letters lowercase, regardless of how the user entered the name. If there is...
Write a java program that reads a given data file called tickets that consists of tickets and the ticket prices. Your program should read the data and compute the find minimum, maximum and average ticket prices and output the report into a file called output.txt. The report file should look exactly (or better than) the one shown below. Your program should implement the Java ArrayList class, Java File I/O, and Java error handling exception. Below is the content of the...
Write a java program for the following: Your program reads an infix expression represented by a string S from the standard input (the keyboard). Then your program converts the infix expression into a postfix expression P using the algorithm. Next, your program evaluates the postfix expression P to produce a single result R. At last, your program displays the original infix expression S, the corresponding postfix expression P and the final result R on the standard output ( the screen...
USE JAVA PLEASE And answer all questions Question 5.1 1. Write a program that reads in a number n and then reads n strings. it then reads a string s from the user and gives you the word that was typed in after s. Example input: 4 Joe Steve John Mike Steve Example output: John Example input: 7 Up Down Left Right North South East Right Example output: North 2. Remember to call your class Program Question 5.2 1. Write...
Java programming: Write a program called Distribution that reads a file of double values into an array and computes and prints the percentage of those numbers within 1 standard deviation (SD), within 2 SDs, and within 3 SDs of the mean. The program should be modular and should at least contain the main method and a method for computing the above percentages given the numbers, the mean, and the standard deviation. Other required statistics should be computed in their own...
Write a program in Java that converts the following do-while loop block to: for loop Write, compile and run below program segment. Make sure to click on the Output Window to input the number. Evaluate the program. Take notes and comment of below program segments of your observations. int x; Scanner input = new Scanner(System.in); x = input.nextInt(); do{ System.out.printf(“%d\n”, x * 2); x++; } while(x < 100);