Question

In: Computer Science

NOTE: Projects will not be graded if: --------------------------- Your complete project is not in a SINGLE...

NOTE: Projects will not be graded if:

---------------------------
Your complete project is not in a SINGLE xxxxxp2.java file, where xxxxx is at most
the 1st the first 5 characters of your last name and p2 is the project number.
Using package or have compile error.
It does not read input from any data file.
It’s not uploaded in canvas.
Those who work jointly, only one should submit and group names must be written at
the bottom of the output.

---------------------------
Write an efficient java program xxxxxp2.java that reads n names and grades from any
data file, stores them in an array and performs selection sort on names and grades (see
below sample input/output). Your constructor should read the input similar to
project-1 solution. The main method should be:
// main program
public static void main(String args[]) throws Exception{
// Create an instance of xxxxxp2 class
xxxxxp2 p = new xxxxxp2();
System.out.print(“Initial input:”);
p.print();
// Selection sort on name
p. sortbyname();
System.out.print(“Input sorted by grade:”);
p.print();
// Selection sort on grade
p. sortbygrade();
System.out.print(“Input sorted by name:”);
p.print();
} // end main
To compile at the command prompt: javac xxxxxp2.java
To execute at the command prompt: java xxxxxp2 < any data file

------------------------------
Sample input:
10 Zaid 75.0 Sason 92.5 Mohamed 88.0 Sarah 100.0 Joel 69.0 Gisela 55.0 Keith 48.4
Suzee 79.2 Steven 95.9 Balal 72.4

Sample Output:
Performing Selection Sort on names and grades.
Prepared by: Date:
Initial input:
Zaid 75.2
Sason 92.5
Mohamed 88.0
Sarah 100.0
Joel 69.0
Gisela 55.3
Keith 62.4
Suzee 79.2
Steven 95.9
Balal 72.4
Input sorted by name
Balal 72.4
Gisela 55.3
Joel 69.0
Keith 62.4
Mohamed 88.0
Sarah 100.0
Sason 92.5
Steven 95.9
Suzee 79.2
Zaid 75.2
Input sorted by grade
Gisela 55.3
Keith 62.4
Joel 69.0
Balal 72.4
Zaid 75.2
Suzee 79.2
Mohamed 88.0
Sason 92.5
Steven 95.9
Sarah 100.0

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

GradeSystem.java

package c13;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

public class GradeSystem {
   private String name[];
   private double grade[];
   private int n;
   GradeSystem(){
       Scanner sc = new Scanner(System.in);
       //loading name of file
       File file = new File("input.txt"); //reading data from this file
       Scanner reader;
       try {
           reader = new Scanner(file);
           n = reader.nextInt();
           name = new String[n];
           grade = new double[n];

           for(int i=0;i<n;i++){
               name[i] = reader.next();
               grade[i] = reader.nextDouble();
           }
           System.out.println("File scan done...");
       } catch (FileNotFoundException e) {
           System.out.println("file not found");
       }
       sc.close();

   }

   private void print() {
       System.out.printf("\n\n%-10s%-10s\n","Name","Grade");
       for(int i=0;i<n;i++){
           System.out.printf("%-10s%-10.2f\n",name[i],grade[i]);
       }
       System.out.println();
   }


   public void sortbygrade(){
       for (int i = 0; i < n-1; i++)
       {
           int min_idx = i;
           for (int j = i+1; j < n; j++)
               if (grade[j] < grade[min_idx])
                   min_idx = j;
           double temp = grade[min_idx];
           grade[min_idx] = grade[i];
           grade[i] = temp;
       }
   }

   private void sortbyname() {
       for (int i = 0; i < n-1; i++)
       {
           int min_idx = i;
           for (int j = i+1; j < n; j++)
               if (name[j].compareTo(name[min_idx])<0)
                   min_idx = j;
           String temp = name[min_idx];
           name[min_idx] = name[i];
           name[i] = temp;
       }
   }

   public static void main(String[] args) {

       // Create an instance of xxxxxp2 class
       GradeSystem p = new GradeSystem();
       System.out.print("Initial input: input.txt");
       p.print();
       // Selection sort on name
       p. sortbygrade();
       System.out.print("Input sorted by grade:");
       p.print();
       // Selection sort on grade
       p. sortbyname();
       System.out.print("Input sorted by name:");
       p.print();
   }

}

input.txt

10 Zaid 75.0 Sason 92.5 Mohamed 88.0 Sarah 100.0 Joel 69.0 Gisela 55.0 Keith 48.4
Suzee 79.2 Steven 95.9 Balal 72.4


Related Solutions

Note: This is a single file C++ project - No documentation is required on this assignment....
Note: This is a single file C++ project - No documentation is required on this assignment. Write a Fraction class whose objects will represent Fractions. Note: You should not simplify (reduce) fractions, you should not use "const," and all of your code should be in a single file. In this single file, the class declaration will come first, followed by the definitions of the class member functions, followed by the client program. You must provide the following member functions: A...
You need to select the work of fiction that you want to use for this assignment. Your topic will graded on originality and the ability to complete the rest of the assignments for the project.
You need to select the work of fiction that you want to use for this assignment. Your topic will graded on originality and the ability to complete the rest of the assignments for the project. Really obvious topics like "Wall Street" or "The Big Short" are 0/30 topics. When you submit your topic I will grade it, you may change your topic and I will regrade it prior to the 2nd. After the due date if you change your topic...
The project will be graded both for mathematical quality and for expository quality.
The project will be graded both for mathematical quality and for expository quality. Look at the six examples in section 4.7 of our text for good ideas about expository style. Notice how the author mixes the necessary mathematical equations with sentences of logic and explanation. Notice that the exposition is almost always in present tense. And, the author frequently uses we referring to the reader and author working together on the steps of solution. These are all standard conventions in...
Short Essay Question​ - GDP​ (10 pts)   ​Note: This question on the test will be graded...
Short Essay Question​ - GDP​ (10 pts)   ​Note: This question on the test will be graded manually. One of the key macroeconomic variables that you have studied in this course is gross domestic product ​(GDP). This macroeconomic variable has been in the economic news headlines frequently here in the US and around the world during this current global​ COVID-19 pandemic. As data are collected and early estimates of GDP​ released, we do not yet know the full extent to which...
Please note that the tax rate for the respective country is 25% Graded Problem: Capital Allowance...
Please note that the tax rate for the respective country is 25% Graded Problem: Capital Allowance Stephen Marsh operates a successful paint distributor business. The accounts for his business in 2017 showed a profit of $5,450,000 after charging: $380,000 depreciation of building, equipment, and furniture; $880,000 for salary to his wife Audrey who supervises the office; $350,000 to his 18-year-old son Paul, and $1,200,000 to himself $120,000 being $78,000 bad debts written off and $42,000 doubtful debts representing 2% of...
Use MS Word to complete "Questions to be Graded: Exercises 31 and 32" in Statistics for...
Use MS Word to complete "Questions to be Graded: Exercises 31 and 32" in Statistics for Nursing Research: A Workbook for Evidence-Based Practice. Submit your work in SPSS by copying the output and pasting into the Word document. In addition to the SPSS output, please include explanations of the results where appropriate.
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
your assignment will be to do a complete SOAPE note on our Covid-19 patient John. Based...
your assignment will be to do a complete SOAPE note on our Covid-19 patient John. Based off of John’s presentation and subjective data so far, begin your SOAP note. You will need to complete a head to toe assessment based off his vital signs, and his presentation discussed in the scenario. As well as his skin and how it appears; His skin is warm to the touch, and mildly diaphoretic. His oral mucous membranes appear ashen, and slightly blue. His...
Start an FC-PC Lab Assignment document and save it to your drive. Note: As you complete...
Start an FC-PC Lab Assignment document and save it to your drive. Note: As you complete the below exercises add them to your Assignment document and save it Create the algorithms in both flowchart and pseudocode form for the following two program requirements:   Given is the array prices with 100 elements(prices[100]). The problem consists of two parts:  1. Find the highest price in the array; and  2. Reduce that price by 10% For any three numbers input by the user, output the...
Your firm is considering the following mutually exclusive projects: Year Project A Project B 0 -$3,300,000...
Your firm is considering the following mutually exclusive projects: Year Project A Project B 0 -$3,300,000 -$3,300,000 1 1,940,000 866,000 2 1,350,000 1,250,000 3 850,000 2,325,000 The firm uses a discount rate of 12.628%. At that discount rate we find that A-Project A is clearly preferred B-Project B is clearly preferred C-the projects have roughly the same NPV's Given that finding, the firm should select ___________because it's NPV is the least sensitive to change A-Project A B-Project B
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT