JAVA
Write a public class call FunnyWord.
class FunnyWord must have a main method.
what it does:
0. prompt user for a String
1. read a String from the user
2. print whether the String is funny or not
3. continue until user enters the word "end"
The String is funny if it looks the same read from left to right or
right to left.
In order to pass all tests you must find funny phrases when spaces,
punctuation and case are ignored (look at the examples).
HINT: you could use the method replaceAll from String in order to
delete all the punctuation marks.
For example:
str.replaceAll(";", "");
returns a string where all semicolons have been replaced by nothing.
or you could use
str.replaceAll("\\W","")
which replaces all punctuation marks
you may also need other methods of String:
toLowerCase(): returns another String in lower case
length(): gives you the length of the String
you can build a String character by character this way:
char c;
String rr;
rr = rr + c; //adds the c at the end of rr
here is a piece of code that uses some of these methods:
public class Traverse{
public static void main(String [] aaa){
String ss = "x y z a b.?/;:'[{]} c defgh";
ss = ss.replaceAll("\\W","");
String new1 = "";
String new2 = "";
for (int i = 0; i < ss.length(); i++){
new1 = new1 + ss.charAt(i);
new2 = ss.charAt(i) + new2;
}
System.out.println(new1);
System.out.println(new2);
}
}
Notice: you cannot use any method called "reverse". That is
considered forbidden knowledge.
Examples
% java FunnyWord Enter a String: Anna
funny!
Enter a String: AnnA AnnA
funny!
Enter a String: A man, a plan, a canal: Panama.
funny!
Enter a String: foo
that is not funny
Enter a String: Annax
that is not funny
Enter a String: end
that is not funny
Code:
/*
*Program to check whether an input string is funny.
*String is funny if it reads same from both left and right
side
*after ignoring spaces,punctualtion and case
*/
import java.util.Scanner;
public class FunnyWord {
public static void main(String[] args) {
String
inputString;
int len;
Scanner input=new
Scanner(System.in);
System.out.println("Java
FunnyWord ");
//run the while loop
till it is true
while(true){
System.out.print("\nEnter a string: "); //prompt user for a
String
inputString=input.nextLine(); //read a String from the user
//remove everything other than word
inputString=inputString.replaceAll("\\W","");
//convert string to lowercase
inputString=inputString.toLowerCase();
//find the length of string
len=inputString.length();
String new1=""; // string from left side variable
String new2=""; // string from right side variable
//run for loop till it traverse the whole inputString
for(int i=0;i<len;i++){
new1=new1+inputString.charAt(i);
new2=inputString.charAt(i)+new2;
}
//if left side string and right side string is equal
if(new1.equals(new2))
System.out.println("Funny!"); //print string is funny
else{
System.out.println("This is not Funny!"); //print string is not
funny
if(inputString.equals("end"))
break; //end if user enters end
}
}
}
}
Output:

JAVA Write a public class call FunnyWord. class FunnyWord must have a main method. what it...
Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** * Program starts with this method. * * @param args A String to be printed backwards */ public static void main(String[] args) { if (args.length == 0) { System.out.println("ERROR: Enter a String on commandline."); } else { String word = args[0]; String backwards = iterativeBack(word); // A (return address) System.out.println("Iterative solution: " + backwards); backwards = recursiveBack(word); // B (return address) System.out.println("\n\nRecursive solution: " +...
Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...
Given code:
/**
* Provides some methods to manipulate text
*
*/
public class LoopyText
{
private String text;
/**
* Creates a LoopyText object with the given text
* @param theText the text for this LoopyText
*/
public LoopyText(String theText)
{
text = theText;
}
//Your methods here
}
Given tester code:
/**
* Tests the methods of LoopyText.
* @author Kathleen O'Brien
*/
public class LoopyTextTester
{
public static void main(String[] args)
{
LoopyText loopy =...
In Java This is the method we did in class. How do I reverse the string "monday"? If I could get the string "onday" reversed (to produce "yadno" then all I have to do is append the first character to make "yadnom". import java.util.Scanner; public class Lab12Num2 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); System.out.println("The string entered was " + s); System.out.println("The string printed backwards is "+ printBackwards(s)); } public static String printBackwards(String one)...
Please write in dr java
Here is the driver:
import java.util.*;
public class SquareDriver {
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String input ="";
System.out.println("Welcome to the easy square program");
while(true)
{
System.out.println("Enter the length of the side of a square or enter QUIT to quit");
try
{
input = keyboard.nextLine();
if(input.equalsIgnoreCase("quit"))
break;
int length = Integer.parseInt(input);
Square s = new Square();
s.setLength(length);
s.draw();
System.out.println("The area is "+s.getArea());
System.out.println("The perimeter is "+s.getPerimeter());
}
catch(DimensionException e)...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()
Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d(); d.employee(56,”ali”); d.department(7,8.6,9); } public void employee(String name, int age) { System.out.println("Your name is"+name); System.out.println(“Age is”+age); } public int department(double d, double t, int a) { System.out.println("I have java exam at 3:00"); Return(1.1); } } V. PROGRAMMING. Write a complete JAVA program to implement the following. 1. Create a class named Exponent. Its main() method accepts an integer value from a user at the keyboard,...
Question 1[JAVA] Add a method in the Main class named getLines() that takes a filename as a String and returns each line in the file in an array. Have each element of the array be a String. Do not include the newline at the end of each line. Use a BufferedReader object to read the file contents. Note, the contents of input.txt will be different (including the number of lines) for each test case. Example: getLines( "input.txt" ) returns (an...
java 1. Write a method header on line three with the following specs: Returns: a boolean Name: beTrue Parameters: none public class Main { { return true; } } 2. Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 public class Main { { String ans = name.toUpperCase();...