Question

In: Computer Science

Provide a comprehensive set of test cases for the two programs below. Do not provide actual...

Provide a comprehensive set of test cases for the two programs below. Do not provide actual test data, but rather describe each test. For example, if one of the programs was to search an array, you might include test cases such as search an array that is in ascending order, search an empty array, search for an element not in the array, etc. a. The program described in Question 4.

Question 4 is

A text file called coit20245.txt consists of N lines each containing a name and a family name as follows. N is largest digit of your student id number. Example of coit20245.txt file: Daniel Atkinson Rob Jackson Brian Lara Write a main() method that reads the rows of coit20245.txt and counts the lines which starts with a first letter of your name. You are to provide class comments that describe what the application does. You are also to provide comments that describe what each significant block of code does.

Note:Java programming language

Solutions

Expert Solution

/* sample data in coit20245.txt

Jack sparrow
Harry porter
Harmoiny Gringer
Albus Dumbledoor
Tony Stark
Peter Parker*/

//program for given task

//importing the scanner class to read file and input from the user
import java.util.Scanner;
//importing the File class for File reading object
import java.io.File;
//importing java.io.* as it contains all the exceptions ;
import java.io.*;//FileNotFoundException; will be in java.io
//Scanner class will throws FileNotFoundException; while reading the content
//file object so we throws FileNotFoundException; at main funtion to skip the
//error showing while compilation and running of code
//creating the main class Name_Check
public class Name_check
{
   //defining the main method
   public static void main(String[] args) throws Exception
   {
       //creating the scanner object to take
       //name of user as input
       Scanner sc=new Scanner(System.in);
       //asking the user to enter name of user
       System.out.print("enter your name:=");
       //taking the input from user
       String name=sc.next();
       //creating the File object to read the file coit20245.txt
       File file=new File("coit20245.txt");
       //now we will pass the instance of File above created to scanner
       //class to read the content of the file
       Scanner file_reader=new Scanner(file);
       //taking the first letter from the name we have taken from user
       char first_letter_from_name=name.charAt(0);
       //initilizing the count variable to count the no of lines starting
       //with first letter of our name
       int count=0;
       //now looping over the contents of file using while loop
       //file_reader.hasNextLine() will return true if file has next line
       //after reading some line
       while (file_reader.hasNextLine())
       {
           String line=file_reader.nextLine();//reading the line from file
           //taking the first letter of the line to compare with first letter
           //taken from our name
           //checking the length of line if it has any character or onlu line
           if (line.length()>0)
           {
               char first_letter_from_line=line.charAt(0);
               //comparing the first letter of name and line for checking
               //whether the line is starting with first letter of name or not
               if (first_letter_from_name==first_letter_from_line)
               {
                   //if first letter of name==first letter of line count will increase
                   count+=1;
               }
           }


       }

       //printing the total no of line that is staring with first letter of name
       System.out.println("No of lines staring with first letter of name:--> "+count);

   }
}

/*output of above code

enter your name:=HArry

No of lines staring with first letter of name:--> 2

*/

//code snippet

//importing the scanner class to read file and input from the user
import java.util.Scanner;
//importing the File class for File reading object
import java.io.File;
//importing java.io.* as it contains all the exceptions ;
import java.io.*;//FileNotFoundException; will be in java.io
//Scanner class will throws FileNotFoundException; while reading the content 
//file object so we throws FileNotFoundException; at main funtion to skip the
//error showing while compilation and running of code
//creating the main class Name_Check
public class Name_check 
{
        //defining the main method
        public static void main(String[] args) throws Exception
        {
                //creating the scanner object to take 
                //name of user as input
                Scanner sc=new Scanner(System.in);
                //asking the user to enter name of user
                System.out.print("enter your name:=");
                //taking the input from user
                String name=sc.next();
                //creating the File object to read the file coit20245.txt
                File file=new File("coit20245.txt");
                //now we will pass the instance of File above created to scanner 
                //class to read the content of the file
                Scanner file_reader=new Scanner(file);
                //taking the first letter from the name we have taken from user
                char first_letter_from_name=name.charAt(0);
                //initilizing the count variable to count the no of lines starting 
                //with first letter of our name
                int count=0;
                //now looping over the contents of file using while loop
                //file_reader.hasNextLine() will return true if file has next line 
                //after reading some line
                while (file_reader.hasNextLine())
                {
                        String line=file_reader.nextLine();//reading the line from file
                        //taking the first letter of the line to compare with first letter 
                        //taken from our name
                        //checking the length of line if it has any character or onlu line
                        if (line.length()>0)
                        {
                                char first_letter_from_line=line.charAt(0);
                                //comparing the first letter of name and line for checking 
                                //whether the line is starting with first letter of name or not
                                if (first_letter_from_name==first_letter_from_line)
                                {
                                        //if first letter of name==first letter of line count will increase
                                        count+=1;
                                }
                        }


                }

                //printing the total no of line that is staring with first letter of name
                System.out.println("No of lines  staring with first letter of name:--> "+count);

        }
}

//screenshots of code

#screenshot of output


Related Solutions

The following is a set of tree-set test programs that show the following outputs: Switch to...
The following is a set of tree-set test programs that show the following outputs: Switch to ArrayList, LinkedList, Vector, TreeMap, and HashMap to display similar output results. Results: Tree set example! Treeset data: 12 34 45 63 Treeset Size: 4 First data: 12 Last Data: 63 Removing data from a tree set Current tree set elements: 12 34 63 Current tree set size :3 Tree set empty. Example code import java.util.Iterator; import java.util.TreeSet; public class TreeDemo2 { public static void...
How do I do  independent t test on the data set below and how do I know...
How do I do  independent t test on the data set below and how do I know if its pooled t test or unrolled t test? Health question for reference: to what extend does the age of MI patients vary by gender Standard deviation: male = 13.944 female= 13.939 mean: male 65.353 female=73.628 Male female 65   88 77   81 78   82 76   66 40   81 83   73 58   64 43   53 39   69 66   67 61   89 49   85 85   81...
The below contains the actual data on COVID-19 cases in Ghana from 1st April, 2020 to...
The below contains the actual data on COVID-19 cases in Ghana from 1st April, 2020 to 25th May, 2020 as presented by the Ghana Health Service. Use the information provided to answer the following questions: Construct a graph to show the trends of the COVID-19 confirmed cases and fatalities in Ghana, and speculate on the factors that might have influenced these trend Date Total confirmed Death Recoveries Test 1-Apr 195 5 3 12046 2-Apr 204 5 3 12046 3-Apr 205...
Which areas do you see healthcare organizations? Countries that have the most comprehensive health programs. Interest...
Which areas do you see healthcare organizations? Countries that have the most comprehensive health programs. Interest groups and health policy Definitions of dependency, developmental vulnerability, dependency vulnerability Definition of allocative tools, redistributive, distributive, regulatory tools
Do research, find actual cases for Wells Fargo that has encountered interest rate risk (general), explain...
Do research, find actual cases for Wells Fargo that has encountered interest rate risk (general), explain how the case relates to Interest Rate Risk Management tools in global finance, and make recommendations for Wells Fargo on how to reduce interest rate risk.
A t-test is used to compare the means of one variable for two groups of cases....
A t-test is used to compare the means of one variable for two groups of cases. As an example, a practical application would be to find out the effect of a new drug on blood pressure. Patients with high blood pressure are randomly assigned into two groups, a placebo group and a treatment group. The placebo group would receive conventional treatment while the treatment group would receive a new drug that is expected to lower blood pressure. After treatment for...
The family college data set contains a sample of 792 cases with two variables, teen and...
The family college data set contains a sample of 792 cases with two variables, teen and parents, and is summarized in Table below. The teen variable is either college or not, where the teenager is labeled as college if she went to college immediately after high school. The parent variable takes the value degree if at least one parent of the teenager completed a college degree. Parents Degree Parents No Degree Total Teen College 231 214 445 Teen Not college...
The test scores of Statistics are listed below, find the mean of the data set that...
The test scores of Statistics are listed below, find the mean of the data set that excluding the outliers: 75,48, 83, 55, 70, 78, 50, 52, 53, 40, 54, 60, 48, 65, 53, 47, 33, 53, 28, 50, 48,55 A. 54.35 B. 56.45 C. 61.15 D. 53.15
in what ways do programs designed to provide assistance (government or otherwise) actually add to poverty....
in what ways do programs designed to provide assistance (government or otherwise) actually add to poverty. What do you see as alternatives to these programs?
Please perform hypothesis test (F-test) Below is the output corresponding to a data set containing one...
Please perform hypothesis test (F-test) Below is the output corresponding to a data set containing one response variable, Y, and 4 predictor variables, var1, var2, var3, and var4. The var1, var2, and var3 predictor variables are quantitative and var4 is qualitative with levels A, B, and C. Only use var1 and var2 Obs Y var1 var2 var3 var4 1 33.2 3.5 9 6.1 A 2 40.3 5.3 20 6.4 A 3 38.7 5.1 18 7.4 A 4 36.8 5.6 27...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT