Home Answers Viewqa Java-Beginners Need help writing a console program

 
 


philippines
Need help writing a console program
0 Answer(s)      a year ago
Posted in : Java Beginners

I need help cant seems to figure it out! Write a program that consists of three classes. The first class will be the actual program.

The second class will simply convert a string to lower case.

The third class will have three methods:

public static String trimmed(String str)

and

public static String trimmed(String str, int len)

and

public static String squeeze(String str)

The 1st trimmed method will return str without leading or trailing whitespace and will return an empty string if str is null.

The 2nd trimmed method will return the first len characters after trimming the string. The 2nd method must make use of the 1st method.

The squeeze method will replace all sequences of 2 spaces with 1 space.

The program will read a file containing the data below (cut and paste it into notepad and save it), and will display each line:

as entered but trimmed and squeezed. as entered but trimmed, squeezed, and shortened to 10 characters as entered but trimmed, squeezed, converted to lower case, and shortened to 20 characters. Data (copy after this line down to (not including) the line that says end data, you will have 5 lines): This is a test, this is only a test!

This test is a test of your Java programming skills! xyz ABCDEFGHIJKLMONPQRSTUVWXYZ1234567890-=_+ ! end data

Here is what i got so far.

import java.io.File;

import java.util.Scanner;

public class {

String s1 = "ABC"; String s2 = LowerCase.convertToLowerCase(s1) }

//this method will convert convert string to lower case

} public class LowerCase { public static String convertToLowerCase(String input) { if (input==null) return ""; return input.toLowerCase(); } }

}

//This method uses an anonymous class to return a lower-cased

//version of a String s

public String toLower(final String s) {

return new Object() {

public String toString() {

return s.toLowerCase();

}

}.toString();

}

public static class StringManipInner {

//This method will trim the white space from the

//beginning and end of the string

public static String trimmed(String s) {

if (s == null) {

return "";

}

return s.trim();

}

//This method will return a trimmed string of size len

public static String trimmed(String s, int len) {

String retVal = StringManipInner.trimmed(s);

if (len > retVal.length()) {

len = retVal.length();

}

return retVal.substring(0,len);

}

//This method will convert all double spaces to a single space

public static String squeeze(String s) {

return s.replace(" ", " ");

}

}

View Answers









Related Pages:
Need help writing a console program
Need help writing a console program  I need help cant seems to figure it out! Write a program that consists of three classes. The first class will be the actual program. The second class will simply convert a string to lower
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need in desperate help in writing a console program
Need in desperate help in writing a console program  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). As they enter the data, assign it to a two
Need help with console program?
Need help with console program?  Write a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed). thanks in advance.   Here is an example that repeatedly
need help on writing a program. - Java Beginners
Writing first Java Program  Hi, I need help to write my first Java Program other then Hello World! Thanks!!  Hi Thanks for choosing roseIndia to get your query solved. check given link to see the solution of your Java
Need help with this!
Need help with this!  Can anyone please help me... for later use. All the students info is put into arrays, but it is not writing to a file at all at this time. Any help would be greatly appreciated, thank you
Need Help in Java programming
Need Help in Java programming  Hello. Can someone please help me with writing the following program Java program that gives assignment details such as:assignment number,assignment name,due date,submission date,percentage marks
need help - Swing AWT
need help  Create a program to correct and grade a set of multiple choice test result. this is a console program that uses JOptionPane dialog boxes.... The program must then ask the user to: "Please enter the number of students". Therafter
File Writing - Java Beginners
File Writing  Hi... I need a syntax or logic or program by which we can write into the desired shell of the Excel file from console window...  Hi friend, I am sending you a link. This is will help you. Please
Need help with my project
Need help with my project  Uses a while loop to perform the following... results to a file in the same directory as the program, placing an appropriate label between each section of output. Note that your program must be able to run
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.  Hello, I would like to know how to write... circumference twice because you need it for both the // console and file I/O
need help with a program - Java Beginners
Java algorithm - need help with a program  Java algorithm - need help with a program
Writing a Program to calculate Circumference of planets reading from a file and writing to new file.
Writing a Program to calculate Circumference of planets reading from a file... because you need it for both the // console and file I/O. // Perform... the comments in my code is an area where I could use the most help. Please Help.I need
need help with a program - Java Beginners
need help with a program   Part I An algorithm describes how... by the user. The output of the program should be the length and width (entered.... First you would need to make up the "test data". For this algorithm, the test data
Adv. Help! Console messenger. How to anticipate if the user is writing something or just waiting for messages
Console messenger. How to anticipate if the user is writing something or just waiting for messages  A console that acts as messenger. The app... will interrupt him. Example: I am writing "How are you?" I received
java program for writing xml file - Java Beginners
java program for writing xml file  Good morning i want to write... table along with their values,so when click some button i need to generate one xml file and storet that in particlar location. Please help me out Thanks
help on writing a javascript - Java Beginners
help on writing a javascript  really have no idea on how to write it if some 1 could help out it would be great of you. thanks in advance...?? 60 D : 0 â?? 40 3. Write a JavaScript program to take as input three
Help with an address book program! - Java Beginners
Help with an address book program!  I have a very long question, but please bare with me. I need help writing a program (or more like putting all... for reading/writing of the contacts data file. I need to add methods for finding
beginner need help with online ordering program please
beginner need help with online ordering program please  I have created a program for an online ordering system and now have to add error handling and a few other things my teacher doesn't teach well is there a template I can go
need help please
need help please  Dear sir, my name is logeswaran. I have a big problem that I can't find the solution for a program. How can I block a user from enter a page second time. Please help me. By the way I'm using Access database
Grant Writing
Grant Writing You need money to start a business, expand or develop your... question. We believe in your dreams and visions of the future and can help you get there. Roseindia's grant writing services
need help creating a lift program - Java Beginners
need help creating a lift program  Classes, Methods, Constructors please i need help to create an elevator program Simulating an Elevator write an Elevator class containing various methods. Then, write a program
hello there i need help
hello there i need help  : i need to do a program like... transaction? thats the problem. I dont know how to start this program because i am a beginner, and aside from that i am really eager to learn java please help
need help with java program as soon as possible
need help with java program as soon as possible  So my assignment is to write a program that used while loops to perform 6 different things. 1. prompt the users to input two integers: firstNum and secondNum (firstNum must be less
I have need to help
I have need to help  Write a program that, for four points A, B, C and P, draws a triangle formed by ABC and a small cross showing the position of P; and displays a line of text indicating which of the following three cases
need help - Java Beginners
need help  Need help in programming in Java  Simple java program that will show the output within quotes using system.out.println... of this program is : " * "" *** "" ***** ""
seriously need help....
seriously need help....  Write a program that will prompt the user... for 30 days. Constraints Your program will be divided into four separate sub... program. Use each of the following Java statements at least once in your program
Need help - Java Beginners
Need help   To Write a Java program that asks the users to enter a m..., respectively. The program stores this matrix into a two dimensional m*n array...; Hi Friend, Please try the following code. We hope that this code will help
Need help in java programming
Need help in java programming  Hello. Can someone please help me with writig the following programm. Assignment 20% Presentation 10% Mini Test 10% Exam 60% Java program that accepts the following details: student
Having a hard time writing program to calculate test scores..........
Having a hard time writing program to calculate test scores..........  i need a program that does this:Standardized Test Scores A local high... the scores are stored in a file (scores.txt) that you will need to download. Input
need help. - Java Beginners
program code and get to the output in uppercase letter.amar
Need help in completing a complex program; Thanks a lot for your help
Need help in completing a complex program; Thanks a lot for your help  Hi, I am currently working on one program which works in this way. 1... content is user inputted and static content is prewritten. 3) We need to search
HIBERNATE IN CONSOLE & SERVLET
advisable to test the program as a console application. Once it is found to work...; console-mode program for adding, finding, deleting, modifying and 'showall' records... HIBERNATE IN CONSOLE & SERVLET ( part-3
Writing a GUI program - Java Beginners
Writing a GUI program  Hello everyone! I'm trying to write a program... if that number is prime or not. When the second button is pressed the program... to write the code for the GUI. Could anyone please help?  Hi Friend
problem in writing coding. Please help me.
problem in writing coding. Please help me.  Hi sir, my name is Logeswaran. I have problem in writing JSP coding for my university assigments. Actually I'm doing a Voting System. I need to know how to write JSP coding
Redirecting the console output into a file in Java
Redirecting the console output into a file in Java  Hi, i coded a program that read specific lines from a text file. It's working well. Now i want to redirect the output of the console to a text file. i used your tutorial
i need help - Development process
i need help  hello, i need help regarding this program. public..., guide me and how my program can take ping for every 5Minutes and store the result in to the files,if i want to do this i must make my program running
i need help - Development process
i need help  hello, i need help regarding this program. this program gives ping to the system. import java.net.*; import java.io.*; import...?   hi subhash hope this code can help you, public class PingTest
Console Input: Scanner
in Java 5) allows simple console and file input. Of course, your program should.../IntroScanner.java // Purpose: Write to and read from the console. // Author : Michael Maus...?"); name = in.nextLine(); // Read one line from the console. in.close
Need *Help fixing this - Java Beginners
Need *Help fixing this  I need to make this program prompt user to login and then set program visibility to be true save volume output to file and maybe add retrieve function //need help with this one badly. Thanks guys for all
Plz Help
Plz Help  Hello Guys!! Plz. Help I need to write a program to display the astrological sign based on your birthday for example If we enter the date of birth in the following format from console--13/08/1990 it should give you
SEO Writing
SEM and SEO Article Writing SEM and SEO article helps your business to grow... the intended traffic through SEM and SEO article writing in addition to other tools... is the demand of SEM and SEO article writing services. A good command over
Please help need quick!!! Thanks
Please help need quick!!! Thanks  hey i keep getting stupid compile... simulation program of sorts here is my code: RentforthBoatRace.java public...(); ^ 6 errors any help would be appreciated guys. Thanks so
New to JSP..need help to make & run a JSP program.
New to JSP..need help to make & run a JSP program.  Hi, I have installed Tomcat 5.5 on my system. Plz help me to make a simple JSP program...:8080/examples/hello.jsp and press enter. You jsp program will then display
java program...need help as soon as possible!!! - Java Beginners
java program...need help as soon as possible!!!  Modify the Lexer (15.... 4. Print each token with line number READLINE: program { int i int j program left: 0 right: 6 line: 1 { left: 8 right: 8: line: 1 int
How to read password from the console
Description: Console class was introduced in jdk 1.6. This class help in taking the input from the console using its readPassword method . Here in this sample program it will ask to feed the password. Note it will accept the password
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another drop.... This name list should get from the database. Please help me. By the way, I'm