(java): using notepad you are to create and save a file(randomCharacters.txt) th
ID: 3626067 • Letter: #
Question
(java): using notepad you are to create and save a file(randomCharacters.txt) that is a one line string made up of at least 25 characters: blanks, numbers(1-9), upper and lower case letters, and special characters. program will then read the file aand modify the file input string so that each lower case letter is converted to upper case. all other characters are to remain unchanged. the converted and non-converted characters are printed. program should modularized with methods having at least one for: obtaining the file name from the keyboard, reading the string from a file, converting the string contents.BE SURE: to write both javadoc(including both pre and post conditions) as well as internal documentation which describes the programs parameters, return values, and logic.
Explanation / Answer
please rate - thanks
you heading says write to a file, but your question has nothing about writing files--message me if any problems
import java.util.*;
import java.io.*;
public class FileIn
{public static void main(String[] args)throws FileNotFoundException
{String filename,buffer,newbuffer;
filename=getFilename(); //get filename
Scanner input=openFile(filename); //open file
buffer=getData(input); //get data
newbuffer=convert(buffer); //convert data
print("Non-Converted characters",buffer); //output original
print("Converted characters",newbuffer); //output converted
}
public static String convert(String buffer) //convert data
{String b2="";
int j;
char c;
for(j=0;j<buffer.length();j++) //for each character
{c=buffer.charAt(j);
if(Character.isLowerCase(c)) //if it's lower case
c=Character.toUpperCase(c); //chage to upper case
b2=b2+c; //form new string
}
return b2;
}
public static void print(String mess,String buffer)
{System.out.println(mess+":");
System.out.println(buffer);
}
public static String getFilename()
{ Scanner in=new Scanner(System.in);
String filename;
System.out.print("Enter file name: ");
filename=in.nextLine();
return filename;
}
public static Scanner openFile(String filename)throws FileNotFoundException
{Scanner input=new Scanner(new File(filename));
return input;
}
public static String getData(Scanner input)
{return input.nextLine();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.