Question

In: Computer Science

Write a Java programs. Q.1. A freshman has 0-29 credits, a sophamore has 30-59, a junior...

Write a Java programs.

Q.1. A freshman has 0-29 credits, a sophamore has 30-59, a junior has 60-89 and a senior has 90+ credits. Write a program to open the file and read all the contents. Report back to the user the number of freshmen, sophomores, juniors and seniors. Output the first and last names of the person with the highest GPA for each of those categories.

Q.2. (Occurrence of each letter) Write a Program that prompts the user to enter a file name and displays the occurrence of each letter in the file. Letters are case insensitive.

Students.java

The file students.txt has the following format on each line

fname(string) lname(string) credits(int) GPA(float) with a single space between each field.

For example

Mitchell Beck 11 2.88
Thelma Colon 43 2.25
Erma Mullins 68 1.98
Pedro Mack 17 1.95

.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// studentsData.java

Mitchell Beck 11 2.88
Thelma Colon 43 2.25
Erma Mullins 68 1.98
Pedro Mack 17 1.95

______________________

// StudentTypeCount.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class StudentTypeCount {

   public static void main(String[] args) {
       //Declaring variables
       int cntFreshman=0,cntSophamore=0,cntJunior=0,cntSenior=0;
       double maxFGPA=-999,maxSGPA=-999,maxJGPA=-999,maxSNGPA=-999;
       String line,fname,lname;
       String mFresh = null,msopho=null,mjuni=null,mseni=null;
       double gpa;
       int credits;
       try {
           //Opening the input file
           Scanner sc=new Scanner(new File("studentsData.txt"));
           //Reading the data from the file
           while(sc.hasNext())
           {
           line=sc.nextLine();
           String array[]=line.split(" ");
           fname=array[0];
           lname=array[1];
           credits=Integer.parseInt(array[2]);          
           gpa=Double.parseDouble(array[3]);
           if(credits>=0 && credits<=29)
           {
               //counting no of freshman
               cntFreshman++;
               //Finding the freshman who got the highest gpa
               if(maxFGPA<gpa)
               {
                   maxFGPA=gpa;
                   mFresh=fname+" "+lname;
               }
           }
           else if(credits>=30 && credits<=59)
           {
               //counting no of sophomore
               cntSophamore++;
               //Finding the sophomore who got the highest gpa
               if(maxSGPA<gpa)
               {
                   maxSGPA=gpa;
                   msopho=fname+" "+lname;
               }
           }
           else if(credits>=60 && credits<=89)
           {
               //counting no of junior
               cntJunior++;
               //Finding the junior who got the highest gpa
               if(maxJGPA<gpa)
               {
                   maxJGPA=gpa;
                   mjuni=fname+" "+lname;
               }
           }
           else if(credits>=90)
           {
               //counting no of senior
               cntSenior++;
               //Finding the senior who got the highest gpa
               if(maxSNGPA<gpa)
               {
                   maxSNGPA=gpa;
                   mseni=fname+" "+lname;
               }
           }
          
          
           }
          
           //Displaying the count of students
           System.out.println("No of Freshman :"+cntFreshman);
           System.out.println("No of Sophomore :"+cntSophamore);
           System.out.println("No of Junior :"+cntJunior);
           System.out.println("No of Senior :"+cntSenior);
           if(cntFreshman>0)
           {
               System.out.println("Among Freshman "+mFresh+" got the highest gpa");
           }
          
           if(cntSophamore>0)
           {
               System.out.println("Among Sophomore "+msopho+" got the highest gpa");
           }
           if(cntJunior>0)
           {
               System.out.println("Among Junior "+mjuni+" got the highest gpa");
           }
           if(cntSenior>0)
           {
               System.out.println("Among Senior "+mseni+" got the highest gpa");
           }
          
          
          
          
       } catch (FileNotFoundException e) {
           System.out.println("File Not Found");
          
       }
      

   }

}
____________________

Output:

No of Freshman :2
No of Sophomore :1
No of Junior :1
No of Senior :0
Among Freshman Mitchell Beck got the highest gpa
Among Sophomore Thelma Colon got the highest gpa
Among Junior Erma Mullins got the highest gpa

_____________________

2)

// aboutComputer.txt

A computer is a device that can be instructed to carry out an
arbitrary set of arithmetic or logical operations automatically.
The ability of computers to follow a sequence of operations
called a program make computers very flexible and useful.
Since ancient times simple manual devices like the abacus
aided people in doing calculations. Early in the Industrial
Revolution, some mechanical devices were built to automate
long tedious tasks, such as guiding patterns for looms.

________________________

// LettersFrequency.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class LettersFrequency {

   public static void main(String[] args) {
       int letter[]=new int[26];
      
String line;   
       try {
           Scanner sc=new Scanner(new File("aboutComputer.txt"));
           while(sc.hasNext())
           {
               line=sc.nextLine().toLowerCase();
               for(int i=0;i<line.length();i++)
               {
                   if(line.charAt(i)>='a' && line.charAt(i)<='z')
                   {
       int val = line.charAt(i) - 97;
      
                       letter[val]++;
                   }
                      
               }
           }
           sc.close();
           System.out.println("Letter\tCount");
           System.out.println("-----\t----");
           for(int i=0;i<letter.length;i++)
           {
               System.out.println((char)(65+i)+"\t"+letter[i]);
           }
          
       } catch (FileNotFoundException e) {
          
           System.out.println("** File Not Found **");
       }
      

   }

}
____________________________

Output:

Letter   Count
-----   ----
A   39
B   6
C   22
D   12
E   44
F   7
G   6
H   7
I   33
J   0
K   3
L   25
M   14
N   21
O   32
P   10
Q   1
R   22
S   25
T   35
U   19
V   5
W   2
X   1
Y   6
Z   0

_______________________


Related Solutions

a) Write C code using if statements to display ‘Freshman, ‘Sophomore’, ‘Junior’ or ‘Senior’ based on...
a) Write C code using if statements to display ‘Freshman, ‘Sophomore’, ‘Junior’ or ‘Senior’ based on what value is in variable classification. Display ‘unknown ’ if classification does not contain ‘f’, ‘s’, ‘j’or ‘r’. Allow upper or lower case in variable color. In other words either ‘r’ or ‘R’ will display ‘Senior’. b) Write C code to do the same thing as the previous problem, but use a switch statement.
Write 2 short Java programs based on the description below. 1) Write a public Java class...
Write 2 short Java programs based on the description below. 1) Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor. The string should contain the following words: {“the”, “quick”, “brown”, “fox”} 2) Write a public Java...
Write two Java programs ( Iterative and Recursive programs ) that solves Tower of Hanoi problem?use...
Write two Java programs ( Iterative and Recursive programs ) that solves Tower of Hanoi problem?use 4 disks and 3 bars
For each problem below, write a java program to solve it, name your programs as PA2_1.java...
For each problem below, write a java program to solve it, name your programs as PA2_1.java and PA2_2.java. 1. We have a steam heating boiler whose bursting pressure is known, but we of course want to use it only at pressures well below this limit. Our engineers recommend a safety factor of 3; that is, we should never exceed a pressure that is one-third of the rated bursting pressure. Write a java program that reads in the rated bursting pressure...
12. Political Party Affiliation and Class level Freshman Sophomore Junior Senior Total Democrat 1 4 5...
12. Political Party Affiliation and Class level Freshman Sophomore Junior Senior Total Democrat 1 4 5 3 13 Republican 4 8 4 2 18 Green 1 3 3 2 9 Libertarian 1 1 2 1 5 Peace/Freedom 2 3 3 2 10 Total 6 15 12 7 55 Perform a hypothesis test to determine whether there is an association between class levels and political party affiliation.
In C++ or Java Write the Greedy programming Algorithm for the 0-1 Knapsack problem.                    (a)...
In C++ or Java Write the Greedy programming Algorithm for the 0-1 Knapsack problem.                    (a) No fraction allowed Max Weight W= 9 item 1: profit $20, weight 2, prof/weight=$10 item 2: profit $30, weight 5, prof/weight=$6 item 3: profit $35, weight 7, prof/weight=$5 item 4: profit $12, weight 3, prof/weight=$4 item 5: profit $3, weight 1, prof/weight=$3
Q 2-29 Why are adjusting entries necessary? Q 2-30 Why aren’t all transactions recorded in the...
Q 2-29 Why are adjusting entries necessary? Q 2-30 Why aren’t all transactions recorded in the gen- eral journal? Q 2-31 Describe the filing deadline for Form 10-K. Q 2-32 Identify the usual forms of a business entity and describe the ownership characteristic of each. Q 2-33 Why would the use of insider information be of concern if the market is efficient?
Considering a Character vector called statusDesc=c(“senior”,”sophomore”,”junior”,”freshman”). Write R code(s) to create a factor called statusFac that...
Considering a Character vector called statusDesc=c(“senior”,”sophomore”,”junior”,”freshman”). Write R code(s) to create a factor called statusFac that will take statusDesc as an argument and has four levels in the order of “freshman,” ”sophomore,” ”junior,” and “senior.” Use the following codes to generate 10 random numbers to represent 10 random ages. set.seed(1) ages=rnorm(10,24,24) Based on the variable ages, use cut() to create a factor called ageFac that has 4 levels “child”,”teen”,”adult”, and “senior”.   The corresponding age ranges are (3,13],(13,18],(18,60],and (60,120]. For example,...
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with...
The goal of this assignment is to write five short Java/Pyhton programs to gain practice with expressions, loops and conditionals. Boolean and integer variables and Conditionals. Write a program Ordered.java that reads in three integer command-line arguments, x, y, and z.   Define a boolean variable isOrdered whose value is true if the three values are either in strictly ascending order  (x < y < z) or in strictly descending order  (x > y > z), and false otherwise. Print out the variable isOrdered...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT