Questions
Hello, How can I make the program print out "Invalid data!!" if the file has a...

Hello,

How can I make the program print out "Invalid data!!" if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero.

The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student grade.

Smith Kelly 438975 98.6 A

Johnson Gus 210498 72.4 C

Reges Stu 098736 88.2 B

Smith Marty 346282 84.1 B

Reges Abe 298575 78.3 C

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is the program.

DRIVER CLASS:

package pkg13_3;
import java.util.*;
import java.io.*;
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException,
InputMismatchException{
try
{
Scanner scan = new Scanner(new File("files.txt"));
ArrayList <Student> elements = new ArrayList<Student>();
  
while(scan.hasNext())
{

String last = scan.next();
String first = scan.next();
int idNum = scan.nextInt();
double perecent = scan.nextDouble();
String grade = scan.next();
elements.add(new Student(last, first, idNum, perecent, grade));
  
}
Student[]element = new Student[elements.size()];
for(int i = 0; i<element.length;i++)
{
element[i] = elements.get(i);
}
System.out.println("Student data by last name: ");
Arrays.sort(element, new LastNameComparator());
for(int i = 0; i<element.length; i++)
{
System.out.println(element[i].toString());
}
  
System.out.println("Student data by first name: ");
Arrays.sort(element, new FirstNameComparator());
for(int i = 0; i<element.length; i++)
{
System.out.println(element[i].toString());
}
  
System.out.println("Student data by student id: ");
Arrays.sort(element, new IDComparator());
for(int i = 0; i<element.length; i++)
{
System.out.println(element[i].toString());
}
  
System.out.println("Student data by percentage: ");
Arrays.sort(element, new PercentageComparator());
for(int i = 0; i<element.length; i++)
{
System.out.println(element[i].toString());
}
  
System.out.println("Student data by percentage: ");
for(int i = 0; i<element.length; i++)
{
System.out.println(element[i].toString());
}
System.out.println("Student data by grade: ");
Arrays.sort(element, new GradeComparator());
for(int i = 0; i<element.length; i++)
{
System.out.println(element[(element.length - 1) -i].toString());
}
  
break;
}
catch(FileNotFoundException e)
{
System.out.println(e.toString());
}
  
catch(InputMismatchException f)
{
System.out.println(f.toString());
}
}
}
STUDENT CLASS:

package pkg13_3;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author user
*/
public class Student {
String firstName, lastName;
int idNum;
double percent;
String grade;
  
public Student(String myFirstName, String myLastName, int id, double pct,
String myGrade)
{
lastName = myFirstName;
firstName = myLastName;
idNum = id;
percent = pct;
grade = myGrade;
  
}
public String getLastName()
{
return lastName;
}
  
public String getFirstName()
{
return firstName;
}
  
public int getID()
{
return idNum;
}
  
public double getPercentage()
{
return percent;
}
  
public String getGrade()
{
return grade;
}
  
public String toString()
{
return lastName + "\t" + firstName + "\t" + idNum + "\t" +
percent + "\t" + grade;

}
}
-------------------------------------------------------------------------------------

LastNameComparator:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkg13_3;
import java.util.*;
/**
*
* @author user
*/
public class LastNameComparator implements Comparator< Student>{
public int compare(Student student1, Student student2)
{
return student1.getLastName().compareTo(student2.getLastName());
}
}

-----------------------------------------------------------------------------------------------------------

First name comparator

--------------------------------------------------------------------------------------------------------------

package pkg13_3;
import java.util.*;
/**
*
* @author user
*/
public class FirstNameComparator implements Comparator< Student>{
public int compare(Student student1, Student student2)
{
return student1.getFirstName().compareTo(student2.getFirstName());
}
}

---------------------------------------------------------------------------------------------------------------

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkg13_3;
import java.util.*;
/**
*
* @author user
*/
public class IDComparator implements Comparator< Student>{
public int compare(Student student1, Student student2)
{
return student1.getID() - (student2.getID());
}
}

-------------------------------------------------------------------------------------------------

Percentage Comparator

_____________________________________________________________

package pkg13_3;
import java.util.*;
/**
*
* @author user
*/
public class PercentageComparator implements Comparator< Student>{
public int compare(Student student1, Student student2)
{
return (int)(student1.getPercentage() - (student2.getPercentage()));
}
}

------------------------------------------------------------------------------------------------------

Grade Comparator:

package pkg13_3;
import java.util.*;
/**
*
* @author user
*/
public class GradeComparator implements Comparator< Student>{
public int compare(Student student1, Student student2)
{
return student1.getGrade().compareTo(student2.getGrade());
}
}

_____________________________________________________________

Thank you

In: Computer Science

Puzzle #4 Five friends each wrote a letter to Santa Claus, pleading for certain presents. What...

Puzzle #4

Five friends each wrote a letter to Santa Claus, pleading for certain presents. What is the full

name of each letter-writer and how many presents did he or she ask for? Kids’ names: Danny,

Joelle, Leslie, Sylvia, and Yvonne. Last names: Croft, Dean, Mason, Palmer, and Willis. Number

of presents requested: 5, 6, 8, 9, and 10.

Clues:

1. Danny asked for one fewer present that the number on Yvonne’s list.

2. The child surnamed Dean asked for one more present than the number on the list written by

the child surnamed Palmer.

3. Sylvia’s list featured the fewest presents, and the letter written by the child surnamed Willis

featured the highest quantity.

4. Joelle asked for one fewer present than the number specified in the Croft child’s letter.

Make your grid to solve:

In: Statistics and Probability

In C++ A new author is in the process of negotiating a contract for a new...

In C++

A new author is in the process of negotiating a contract for a new romance novel. The publisher is offering three options.

  • In the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published.
  • In the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold.
  • In the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000.

The author has some idea about the number of copies that will be sold and would like to have an estimate of the royalties generated under each option.

Instructions

Write a program that prompts the author to enter:

  1. The estimated number of copies that will be sold.
  2. The net price of each copy of the novel

The program then outputs:

  1. The royalties under each option
  2. The best option the author could choose.
    • Ex. If option 1 is the best, output Option 1 is the best

(Use appropriate named constants to store the special values such as royalty rates and fixed royalties.)

Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.

Example input:

120
22.99

Expected Output:

25000.0

344.8

275.8

Option 1 is the best

In: Computer Science

(C++) Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined...

(C++) Redo Programming Exercise 16 of Chapter 4 so that all the named constants are defined in a namespace royaltyRates. Instructions for Programming Exercise 16 of Chapter 4 have been posted below for your convenience. Exercise 16 A new author is in the process of negotiating a contract for a new romance novel.

The publisher is offering three options. In the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. In the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. In the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. The author has some idea about the number of copies that will be sold and would like to have an estimate of the royalties generated under each option. Write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. The program then outputs the royalties under each option and the best option the author could choose. (Use appropriate named constants to store the special values such as royalty rates and fixed royalties.)

An input of: 20, 5

Should have an output of:

Royalty option1: 25000.00
Royalty option2: 12.50
Royalty option3: 10.00

In: Computer Science

In this experiment, the motion of a fan cart with a mass of 480g was measured...

In this experiment, the motion of a fan cart with a mass of 480g was measured as it accelerated from rest, along a horizontal track. These results were calculated from data collected by LoggerPRO.

                                                                Trial 1            Trial 2            Trial 3

Acceleration from x-t graph (m/s2)     0.642             0.622             0.651

Acceleration from v-t graph (m/s2)     0.618             0.664             0.604

A new experiment will be run, with these changes:

  1. A mass of 120g is added to the cart (we experimented with different masses last week), and
  2. The track is inclined at 4.5° (we experimented with carts on inclines earlier in the course)

Will the fan cause the same cart to accelerate up the incline, down the incline, or will the cart remain at rest? Show your calculations, and explain fully in words.

In: Physics

The new economy after the American Civil presented immense changes to industry, technology, occupations, and life...

The new economy after the American Civil presented immense changes to industry, technology, occupations, and life in general. As you know from your reading, these changes included the proliferation of factories and large corporations, as well as rising economic inequalities.

With these new challenges, we also begin to see new visions for how society can best address societal problems. This week's primary source readings (Voices of Freedom, Foner) present you with various thinkers and their views on the Gilded Age.

--

Discussion

Select two of the primary sources from this week's Voices of Freedom and answer the following questions:

Source #1:

1) According to this author, what are the main challenges of the Gilded Age Economy, who are being impacted, and what solutions does the author offer?

2) How does this author understand freedom in the Gilded Age?

Source #2:

3) According to this author, what are the main challenges of the Gilded Age Economy, who are being impacted, and what solutions does the author offer?

4) How does this author understand freedom in the Gilded Age?

In: Economics

This task is about classes and objects, and is solved in Python 3. We will look...

This task is about classes and objects, and is solved in Python 3.

We will look at two different ways to represent a succession of monarchs, e.g. the series of Norwegian kings from Haakon VII to Harald V, and print it out like this:

King Haakon VII of Norway, accession: 1905

King Olav V of Norway, accession: 1957

King Harald V of Norway, accession: 1991

>>>

Make a class Monarch with three attributes: the name of the monarch, the nation and year of accession. The class should have a method write () which prints out the information on a line like in the example. It should also have the method _init_ (…), so that you can create a Monarch instance by name, nation and year of accession as arguments. Example:

haakon = Monarch("Norway","King Haakon VII",1905)

Here, the variable haakon will be assigned to the Monarch object for King Haakon VII. Now the series of kings can be represented in a variable series of kings, that contains a list of the three monarchs, in the right order. Finally, the program will print the series of kings as shown above.

In: Computer Science

When answering the following questions, explain the relationship to critical infrastructure protection. Describe five of the...

When answering the following questions, explain the relationship to critical infrastructure protection.

Describe five of the 11 transportation infrastructure in terms of risk and protection - roads, railways, walkways, bridges and tunnels, stations, airports, air routes, waterways, ports, cycling infrastructure, and living streets.

In: Civil Engineering

which statements are true about Python functions? a)Different functions cannot use same function name b)a function...

which statements are true about Python functions?

a)Different functions cannot use same function name

b)a function always returns some value

c)different function cannot use the same variable names

d) function must use the same parameter names as the corresponding variables in the caller

what benefits does structuring a program through defining functions bring?

a) there is a possibility of reducing the number of variables and/or objects that must be managed at any cost at any one point

b)the program is easier to maintain

c)program with function executes faster

d)the program is easier to debug

in which scenario(s) should the sentinel value be set to -1 to terminate data entry

a)exam scores which can be negative but cannot be more than 100

b) participant name of participants who registered for a run

c)the rainfall data for days it rained

d)the weight of student waiting to undergo a medical examination.

suppose d = {"a": "apple", "b": "banana", "c": "cherry"}

which statement form a list [["a": "apple"], ["b": "banana"[, ["c": "cherry"]]

a) [[k,d[k]] for k in d.keys() ]

b) [[k,v] for k, v in d.items() ]

c) [[d,v] for v in d.values() ]

d) [[k,[0]], k[1]] for k in d]

In: Computer Science

Experiment 7: Thin Layer Chromatography What is the name of the technique you will be using...

Experiment 7: Thin Layer Chromatography

  1. What is the name of the technique you will be using in experiment No.7 lab?
    1. Thin Layer Chromatography
    2. Mass Spectrometry
    3. Thick Liquid Calorimetry
    4. Liquid Chamber Chromatography
  1. TLC plates separate molecules on the basis of:
    1. Polarity
    2. Color
    3. Size
    4. Bond orientation
  1. The mixture is dissolved in a fluid called the ___________ phase, which carries it through   a structure holding another material called the __________ phase.

  1. The polarity of a bond between two elements can be best determined by
  1. The difference in electronegativity between the elements
  2. The difference in first ionization energy between the elements
  3. The number of electrons shared in the bond
  4. The difference in atomic radius between the elements

  1. EXPLAIN the phrase “like dissolves like.”

In: Other