Question

please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the...

please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :(

the program is supposed to read from my input file and do the following

       1) print out the original data in the file without doing anything to it.

       2) an ordered list of all students names (last names) alphabetically and the average GPA of all student togther .

3) freshman list in alphabeticalorder by last name with the average GPA of the freshmen togther .

4) sophomore list in alphabetical order by last name with the average GPA of the sophomores togther .

5)The junior list in alphabetical order by last name with the average GPA of the juniors.

6)The senior list in alphabetical order by last name with the average GPA of the seniors.

_______________________________________________

my input file is below

_________________

Williams,Leonard Freshman 1.85
Smith,Sheila Senior 2.99
Anderson,Andy Sophomore 3.01
Wiser,Bud Freshman 4.00
Robertson,Jully Junior 2.78
Koran,korn Junior 3.50
smith,sam Junior 2.14
Johnson,Jim Junior 3.05
Johnson,Jane Junior 3.75
Potter,Pam Senior 2.98
Brown,Bill Sophomore 2.55
Crooks,Cathy Freshman 1.99
Gregg,Howard Senior 2.44
Nicholas,Judy Senior 3.69
White,Bob Sophomore 1.64
Walsh,Fred Junior 4.00
Dennis,Susan Senior 2.06
Roberts,Rachel Sophomore 4.00
Fredericks,Mary freshman 2.89
Holmes,Wendy Senior 2.56
Edwards,James Sophomore 3.00,Barbara Sophomore 3.67
Brown,David Freshman 2.00
Williamson,Walt Sophomore 2.95
Carson,Jim Sophomore 2.03

_______________

and my code is below

___________________

//GPACalculation.java FILE

import java.util.*;

import java.io.*;

public class GPACalculation

{

public static void main(String args[])

{

File file;

GPAInformation gpas[] = new GPAInformation[80];

ArrayList<GPAInformation> fresherMan = new ArrayList<GPAInformation>();

ArrayList<GPAInformation> senior = new ArrayList<GPAInformation>();

ArrayList<GPAInformation> junior = new ArrayList<GPAInformation>();

ArrayList<GPAInformation> sophomore = new ArrayList<GPAInformation>();

String array[] = new String[3];

String line;

Scanner in;

double average=0;

int count = 0;



System.out.println("Information in the text file is: ");

try

{

file = new File("program1.txt");

in = new Scanner(file);

while (in.hasNextLine())

{

line = in.nextLine();

array = line.split("\t");

System.out.println(line);

GPAInformation newGPA = new GPAInformation();

newGPA.setName(array[0].trim());

newGPA.setGradeLevel(array[1].trim());

newGPA.setGpaValue(Double.parseDouble(array[2].trim()));

gpas[count] = newGPA;

count++;

}

in.close();

}

catch (Exception e)

{

e.printStackTrace();

}



System.out.println();



System.out.println("The ordered list is: ");

gpas = selectionSort(gpas, count);

print(gpas, count);

average = gpaAverage(gpas, count);



System.out.println("The average value of GPA of overall students is: "+average);

System.out.println();



System.out.println("The ordered list of freshman: ");

fresherMan = getGPAInformation(gpas, count, "Freshman");

printList(fresherMan);

average = gpaAverage(fresherMan);

System.out.println("The average value of GPA of overall freshman is: "+average);

System.out.println();



System.out.println("The ordered list of sophomores : ");

sophomore = getGPAInformation(gpas, count, "Sophomore");

printList(sophomore);

average = gpaAverage(sophomore);

System.out.println("The average value of GPA of overall sophomore is: "+average);

System.out.println();



System.out.println("The ordered list of junior man: ");

junior = getGPAInformation(gpas, count, "Junior");

printList(junior);

average = gpaAverage(junior);

System.out.println("The average value of GPA of overall junior is: "+average);

System.out.println();



System.out.println("The ordered list of seniour man: ");

senior = getGPAInformation(gpas, count, "senior");

printList(senior);

average = gpaAverage(senior);

System.out.println("The average value of GPA of overall senior is: "+average);

System.out.println();

}

public static ArrayList<GPAInformation> getGPAInformation(GPAInformation[] gpas, int count, String level)

{

ArrayList<GPAInformation> newList = new ArrayList<GPAInformation>();

for (int i = 0; i < count; ++i)

{

if (gpas[i].getGradeLevel().equalsIgnoreCase(level))

{

newList.add(gpas[i]);

}

}

return newList;

}

// Selection sort code

public static GPAInformation[] selectionSort(GPAInformation[] studs,int counts)

{

for (int i = 0; i < counts; ++i)

{

int minIndex = i;

for (int j = i + 1; j < counts; ++j)

{

if (studs[j].name.equalsIgnoreCase(studs[minIndex].name))

;

minIndex = j;

}

swap(studs, minIndex, i);

}

return studs;

}

private static void swap(GPAInformation[] studs, int i, int j)

{

GPAInformation temp = studs[i];

studs[i] = studs[j];

studs[j] = temp;

}

public static double gpaAverage(GPAInformation[] studs, int counts)

{

double avg = 0;

double total = 0;

for (int i = 0; i < counts; ++i)

{

total += studs[i].getGpaValue();

}

avg = total / counts;

return avg;

}

public static double gpaAverage(ArrayList<GPAInformation> list)

{

double avg = 0;

double total = 0;

for (int i = 0; i < list.size(); ++i)

{

total += list.get(i).getGpaValue();

}

avg = total / list.size();

return avg;

}

public static void print(GPAInformation[] studs, int counts)

{

for(int i=0;i<counts;i++)

System.out.println(studs[i]);

}

public static void printList(ArrayList<GPAInformation> list)

{

for(int i=0;i<list.size();i++)

System.out.println(list.get(i));

}

}

________________ CONSTRUCTOR FILE_______

//GPAInformation.java

public class GPAInformation

{

String name, GradeLevel;

double gpaValue;

public GPAInformation()

{

name = "";

GradeLevel = "";

gpaValue = 0;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public String getGradeLevel()

{

return GradeLevel;

}

public void setGradeLevel(String gradeLevel)

{

GradeLevel = gradeLevel;

}

public double getGpaValue()

{

return gpaValue;

}

public void setGpaValue(double gpaValue)

{

this.gpaValue = gpaValue;

}

public String toString()

{

return getName() + "\t\t" + getGradeLevel() + "\t\t" + getGpaValue();

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// GPAInformation.java

public class GPAInformation

{

String name, GradeLevel;

double gpaValue;

public GPAInformation()

{

name = "";

GradeLevel = "";

gpaValue = 0;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public String getGradeLevel()

{

return GradeLevel;

}

public void setGradeLevel(String gradeLevel)

{

GradeLevel = gradeLevel;

}

public double getGpaValue()

{

return gpaValue;

}

public void setGpaValue(double gpaValue)

{

this.gpaValue = gpaValue;

}

public String toString()

{

return getName() + "\t\t" + getGradeLevel() + "\t\t" + getGpaValue();

}

}

// GPACalculation.java

import java.util.*;

import java.io.*;

public class GPACalculation

{

public static void main(String args[])

{

File file;

GPAInformation gpas[] = new GPAInformation[80];

ArrayList<GPAInformation> fresherMan = new ArrayList<GPAInformation>();

ArrayList<GPAInformation> senior = new ArrayList<GPAInformation>();

ArrayList<GPAInformation> junior = new ArrayList<GPAInformation>();

ArrayList<GPAInformation> sophomore = new ArrayList<GPAInformation>();

String array[] = new String[3];

String line;

Scanner in;

double average=0;

int count = 0;

System.out.println("Information in the text file is: ");

try

{

file = new File("program1.txt");

in = new Scanner(file);

while (in.hasNextLine())

{

line = in.nextLine();

array = line.split(" "); // The problem was that you were trying to split the line by a tab, whereas the input file doesn't have a tab anywhere

System.out.println(line);

GPAInformation newGPA = new GPAInformation();

newGPA.setName(array[0].trim());

newGPA.setGradeLevel(array[1].trim());

newGPA.setGpaValue(Double.parseDouble(array[2].trim()));

gpas[count] = newGPA;

count++;

}

in.close();

}

catch (Exception e)

{

e.printStackTrace();

}

System.out.println();

System.out.println("The ordered list is: ");

gpas = selectionSort(gpas, count);

print(gpas, count);

average = gpaAverage(gpas, count);

System.out.println("The average value of GPA of overall students is: "+average);

System.out.println();

System.out.println("The ordered list of freshman: ");

fresherMan = getGPAInformation(gpas, count, "Freshman");

printList(fresherMan);

average = gpaAverage(fresherMan);

System.out.println("The average value of GPA of overall freshman is: "+average);

System.out.println();

System.out.println("The ordered list of sophomores : ");

sophomore = getGPAInformation(gpas, count, "Sophomore");

printList(sophomore);

average = gpaAverage(sophomore);

System.out.println("The average value of GPA of overall sophomore is: "+average);

System.out.println();

System.out.println("The ordered list of junior man: ");

junior = getGPAInformation(gpas, count, "Junior");

printList(junior);

average = gpaAverage(junior);

System.out.println("The average value of GPA of overall junior is: "+average);

System.out.println();

System.out.println("The ordered list of seniour man: ");

senior = getGPAInformation(gpas, count, "senior");

printList(senior);

average = gpaAverage(senior);

System.out.println("The average value of GPA of overall senior is: "+average);

System.out.println();

}

public static ArrayList<GPAInformation> getGPAInformation(GPAInformation[] gpas, int count, String level)

{

ArrayList<GPAInformation> newList = new ArrayList<GPAInformation>();

for (int i = 0; i < count; ++i)

{

if (gpas[i].getGradeLevel().equalsIgnoreCase(level))

{

newList.add(gpas[i]);

}

}

return newList;

}

// Selection sort code

public static GPAInformation[] selectionSort(GPAInformation[] studs,int counts)

{

for (int i = 0; i < counts; ++i)

{

int minIndex = i;

for (int j = i + 1; j < counts; ++j)

{

if (studs[j].name.equalsIgnoreCase(studs[minIndex].name))

;

minIndex = j;

}

swap(studs, minIndex, i);

}

return studs;

}

private static void swap(GPAInformation[] studs, int i, int j)

{

GPAInformation temp = studs[i];

studs[i] = studs[j];

studs[j] = temp;

}

public static double gpaAverage(GPAInformation[] studs, int counts)

{

double avg = 0;

double total = 0;

for (int i = 0; i < counts; ++i)

{

total += studs[i].getGpaValue();

}

avg = total / counts;

return avg;

}

public static double gpaAverage(ArrayList<GPAInformation> list)

{

double avg = 0;

double total = 0;

for (int i = 0; i < list.size(); ++i)

{

total += list.get(i).getGpaValue();

}

avg = total / list.size();

return avg;

}

public static void print(GPAInformation[] studs, int counts)

{

for(int i=0;i<counts;i++)

System.out.println(studs[i]);

}

public static void printList(ArrayList<GPAInformation> list)

{

for(int i=0;i<list.size();i++)

System.out.println(list.get(i));

}

}

<terminated> GPACalculation [Java Application] /usr/lib/jvm/java-7 Information in the text file is: Williams, Leonard Freshma

The ordered list of freshman: Williams, Leonard Wiser,Bud Crooks,Cathy Fredericks,Mary Brown,David The average value of GPA o

Add a comment
Know the answer?
Add Answer to:
please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • *JAVA Prompt the user for a movie name. Output the three movies that come alphabetically before...

    *JAVA Prompt the user for a movie name. Output the three movies that come alphabetically before the one entered. I need help correcting my code. I'm unsure why I am getting a name, year, and genre in my output. Input: Jericho Output: Similar title finder. Enter a movie name.\n Here are the 3 movies that are listed before the one you entered\n Jeremy Paxman Interviews...\n Jeremy Taylor\n Jeremy Vine Meets...\n Current output: Similar title finder. Enter a movie name.\n Here...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

  • Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Wr...

    Trying to practice this assignment Argument list: the *yahoonews.txt Data file: yahoonews.txt Write a program named WordCount.java, in this program, implement two static methods as specified below: public static int countWord(Sting word, String str) this method counts the number of occurrence of the word in the String (str) public static int countWord(String word, File file) This method counts the number of occurrence of the word in the file. Ignore case in the word. Possible punctuation and symbals in the file...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • This is the question: These are in Java format. Comments are required on these two Classes...

    This is the question: These are in Java format. Comments are required on these two Classes (Student.java and StudentDemo.java) all over the coding: Provide proper comments all over the codings. --------------------------------------------------------------------------------------------------------------- import java.io.*; import java.util.*; class Student {    private String name;    private double gradePointAverage;    public Student(String n , double a){    name = n;    gradePointAverage = a;    }    public String getName(){ return name;    }    public double getGradePointAverage(){ return gradePointAverage;    }   ...

  • JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out...

    JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowestgpa. In the attached zip file, you will find two files HighestGPA.java and students.dat. Students.dat file contains names of students and their gpa. Check if the code runs correctly in BlueJ or any other IDE by running the code. Modify the data to include few more students and their gpa. import java.util.*; // for the Scanner class...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT