Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in the following language: Java Your program will consist of a f

ID: 3794474 • Letter: W

Question

Write a program in the following language: Java

Your program will consist of a function that accepts two strings. Each string is the name of
a file. The first is the name of an input file and the second is the name of an output file. Name
the function hw1. (Note that your program can also make use of other helper functions. Just
make sure function hw1 takes as arguments the input file and output file that are specified in the
programe)
A pangram is a sentence that contains all the letters of the English alphabet at least once. For
example, the quick brown fox jumps over the lazy dog is a pangram. The program you are to write
must read in an input file (input.txt - a plain text file which contains 5 sentences), line by line and
check if the line read is a pangram or not. If the sentence read is a pangram, it writes true to the
output file. If it is not, it writes false to the output file.
For example, if input.txt contains:
we promptly judged antique ivory buckles for the next prize.
how quickly daft jumping zebras vex.
pottery is an art.
crazy fredrick bought many very exquisite opal jewels.
mr. dumbledore is a funny name for a dog.
Then your program must output the following to the output.txt:
true
true
false
true
false
NOTE: Output is case sensitive { please use all lower case in the output file. The example
provided here is formatted for human readability. Please look at the sample input
output files to see the precise formatting.

Java Specific Instructions
Your code should be written in hw1.java. Create a hw1 class with a static method hw1 that takes
in two strings as arguments: the first for the name of input file and second for the name of output
file.
You should have another class with a main method to test your code in a separate file. This
file should not be submitted { it is for your testing purposes only.
Skeleton Code:
Define hw1.java as:
public class hw1 {
public static void hw1(inFile, outFile){
//function defintion here
}
}
Define Tester.java as: (this is a separate file)
public class Tester{
public static void main(String[] args){
...
String input = "input.txt";
String output = "output.txt";
/* You can also read input and output as command line arguments*/
hw1.hw1(input, output);
}
}

Explanation / Answer

package sample;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.IOException;

import java.io.OutputStreamWriter;

public class hw1 {

public static void hw1(String inFile,String outFile){

try {

File file = new File(inFile);

FileReader fileReader = new FileReader(file);

BufferedReader bufferedReader = new BufferedReader(fileReader);

String line;

File fout = new File("out.txt");

FileOutputStream fos = new FileOutputStream(fout);

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

while ((line = bufferedReader.readLine()) != null) {

bw.write(isPangram(line));

bw.newLine();

}

fileReader.close();

bw.close();

} catch (IOException e) {

e.printStackTrace();

}

}

public static String isPangram(String s) {

if (s.length() < 26) {

return "false";

}

for (char ch = 'A'; ch <= 'Z'; ch++) {

if (s.indexOf(ch) < 0

&& s.indexOf((char) (ch + 32)) < 0) {

return "false";

}

}

return "true";

}

}

package sample;

public class lib{

public static void main(String[] args){

String input = "C:\Users\Sandeep\Desktop\input.txt";

String output = "C:\Users\Sandeep\Desktop\output.txt";

hw1.hw1(input,output);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote