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

Okay, so this is Activity 2 of my lab... Please, and thank you in advance! The .

ID: 3566400 • Letter: O

Question

Okay, so this is Activity 2 of my lab... Please, and thank you in advance!

The .txt file provided to us is at the bottom. The main and the other .java file is posted with Activity 1 here: http://www.chegg.com/homework-help/questions-and-answers/really-need-help-java-lab-missed-couple-lectures-m-completely-lost-try-question-please-com-q6082051

Activity 2: Reading from and Writing to Text Files (3 marks)

In q2 contains a skeleton of the program that writes a program that will read a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). You can find a file called

In q2 contains a skeleton of the program that writes a program that will read a file of student academic credit data and create a list of students on academic warning. The list of students on warning will be written to a file. Each line of the input file will contain the student name (a single String with no spaces), the number of semester hours earned (an integer), the total quality points earned (a double). You can find a file called "student.txt" in lab5 package. The program should compute the GPA (grade point or quality point average) for each student (the total quality points divided by the number of semester hours) then write the student information to the output file if that student should be put on academic warning. A student will be on warning if he/she has a GPA less than 1.5 for students with fewer than 30 semester hours credit, 1.75 for students with fewer than 60 semester hours credit, and 2.0 for all other students. Do the following:

Explanation / Answer

import java.io.*;

import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Scanner;

public class lab5 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Please enter a number (1~2) to select a question:");
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
questions q = new questions();

int quest = scan.nextInt();

switch(quest)
{
case 1: q.q1(); break;
case 2: q.q2(); break;
}
}

}

class questions {

void q1()
{
int[] counts = new int[26];
Scanner scan = new Scanner(System.in);

//get word from user
System.out.print("Enter a single word(letters only, please)");
String word = scan.nextLine();

//convert to all upper case
word = word.toUpperCase();

//count frequency of each letter in string
for(int i=0; i < word.length(); i++)
{
try {
counts[word.charAt(i) - 'A']++;
}
catch(Exception e){
System.out.println("Not a Letter");
}
}


//print frequencies
System.out.println();
for(int i=0; i < counts.length; i++)
{
if(counts[i] != 0)
{
System.out.println((char)(i+'A')+":" + counts[i]);
}
}
}

void q2()
{
int creditHrs; // number of semester hours earned
double qualityPts; // number of quality points earned
double gpa; // grade point (quality point) average

String line, name, inputName = "students.txt";
String outputName = "warning.txt";


try{
Scanner scr = new Scanner(new File(inputName));
try{
PrintWriter outfile = new PrintWriter(new FileWriter(outputName));
outfile.println("Student on Academic Warning");
outfile.println();

//Print a header to the output file
//Process the input file, one token at a time
while(scr.hasNext()) {
try {
line = scr.nextLine();
name = line.split(" ")[0];
creditHrs = Integer.parseInt(line.split(" ")[1]);
qualityPts = Double.parseDouble(line.split(" ")[2]);

gpa = qualityPts / creditHrs;
if (creditHrs <= 30 && gpa < 1.5) {
outfile.write(name);
outfile.println();
} else if (creditHrs <= 60 && creditHrs > 30 && gpa < 1.75) {
outfile.write(name);
outfile.println();
} else if (gpa < 2.00) {
outfile.write(name);
outfile.println();
}
}
catch (InputMismatchException e){
System.out.println("The input is not legal");
}
}

scr.close();
outfile.close();

}
catch (IOException e){
System.out.println("Something is wrong with the input or output streams");
}
}
catch(FileNotFoundException e){
System.out.println("The input file is not found");
}

}
}

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