Menu

[Solved]Need Classes Tests Thanks Much Please Let Know S Anything Else Need Negativevalueexception Q37110507

I need the below classes/tests. Thanks so much! Please let meknow if there’s anything else you need.

NegativeValueException.java
NegativeValueExceptionTest.java
VehiclesPart3.java
VehiclesPart3Test.java

* NegativeValueException.java Requirements and Design: NegativeValueException is a user defined exception created by extendin

car-new Car (Jackson, Bo, 2012 Toyota Camry, -25000, false) Car catch (NegativeValueException e) thrown = true ; Assert.a

VehiclesPart3.java Requirements and Design: The VehiclesPart3 class has only a main method as described below. In addition to

readVehicleFile method of the UseTaxListclasspublic void readVehicleFile(String fileNameIn) throws FileNotFoundException { Scanner fileScan new Scanner (new File(fileName

Truck t1new Truck (owner, yMM, value, altFuel, tons); addVehicle(t1); break case S String tinput.next().trim(); String a -i

addExcludedRecord(ein: In bob); catch (NoSuchElementException e) addExcludedRecord (e in: In bob); catch (NegativeValueExc

* NegativeValueException.java Requirements and Design: NegativeValueException is a user defined exception created by extending the Exception class with an empty body. The constructor for NegativeValueException should be parameterless, but it should invoke the super constructor with the String message “Numeric values must be nonnegative”. The inherited toString0 value of a NegativeValueException will be the name of the exception and the message. This exception is to be caught in the readVehicleFile method in the UseTaxList class when a line of input data contains a negative value for one of the numeric input values: value, tons, axles, engineSize. The NegativeValueException is to be thrown in the “vehicle” constructor that is responsible for setting the field in question. The following shows how the constructor would be called: new NegativeValueException ) Fora similar constructor, see InvalidLengthException.java in Examples Polygons from this week’s lecture notes on Exceptions Page 2 of 8 roiect: Vehicles – Part 3 Page 3 of 8 Testing: Here is an example of a test method that checks to make sure a negative value for value in the constructor for Vehicle throws a NegativeValueException. Note that creating a Car invokes the constructor in Vehicle. You should consider adding test methods to check for negative values for the other numeric fields. @Test public void negativeValueExceptionTest) boolean thrown = false; try car-new Car (“Jackson, Bo”, “2012 Toyota Camry”, -25000, false) Car catch (NegativeValueException e) thrown = true ; Assert.assertTrue (“Expected NegativeValueException to be thrown.”, thrown) /*or alternatively: / Assert.assertEquals(“Expected NegativeValueException to be thrown.”, true, thrown) VehiclesPart3.java Requirements and Design: The VehiclesPart3 class has only a main method as described below. In addition to the specifications in Project 10, the main method should be modified to catch and UseTaxList class Page 4 of 8 Project: Vehicles – Part 3 Page 5 of 8 In Part 3, main reads in the file name from the command line as was done in Vehicles – Part 2, creates an instance of UseTaxList, and then calls the readVehicleFile method in the UseTaxList class to read in the data file. After successfully reading in the file, the main method then prints the summary, vehicle list by owner, vehicle list by use tax, and the list of excluded records. The main method should not include the throws FileNotFoundException in the declarationInstead, the main method should include a try-catch statement to catch o class. This exception will occur when an incorrect file name is passed to the readVehicleFile method_After this FileNotFoundException is caught, print the messages below and end *File not found Program ending. Also, if the user runs the program without a command line argument (e.g., args.length 0), main should print the following message and end. File name not provided by command line argument. Program ending. public void readVehicleFile(String fileNameIn) throws FileNotFoundException { Scanner fileScan new Scanner (new File(fileNameIn) taxDistrict- fileScan.nextLine(); while (fileScan.hasNextO) bob fileScan.nextLine().trim(); String try = Scanner input – new Scanner(bob).useDelimiter(“;”); char vehicleTypeinput.next().toUpperCase().trim).charAt (0); String owner- input.next().trim(); String yMM-input.next().trim); String vinput.next().trim(); String aFinput.next().trimO; boolean altFuel false; if (aF.equals(“true”)) altFuel – true; double value – Double.parseDouble(v); switch (vehicleType) case “C’ Car c1- new Car(owner, yMM, value, altFuel); addVehicle(c1); break case T’: String tt input.next).trim); double tonsDouble.parseDouble(tt); Truck t1new Truck (owner, yMM, value, altFuel, tons); addVehicle(t1); break case ‘S’ String tinput.next().trim(); String a -input.next().trim(); double tons2 = Double . parseDouble(t); int axle = Integer.parseInt(a); SemiTractorTrailer s1 new SemiTractorTrailer (owner, yMM, value, altFuel, tons2, axle); addVehicle(s1); break case ‘M’ String sinput.next().trim); int size Integer.parseInt(s); Motorcycle m1 -new Motorcycle (owner, yMM, value, altFuel, size); addVehicle(m1); break default addExcludedRecord(“Invalid Vehicle Category in: n” break bob); : J catch (NumberFormatException e) { addExcludedRecord(e”in: In” bob); catch (NoSuchElementException e) addExcludedRecord (e in: In” bob); catch (NegativeValueException e addExcludedRecord (e in: In” bob); Show transcribed image text * NegativeValueException.java Requirements and Design: NegativeValueException is a user defined exception created by extending the Exception class with an empty body. The constructor for NegativeValueException should be parameterless, but it should invoke the super constructor with the String message “Numeric values must be nonnegative”. The inherited toString0 value of a NegativeValueException will be the name of the exception and the message. This exception is to be caught in the readVehicleFile method in the UseTaxList class when a line of input data contains a negative value for one of the numeric input values: value, tons, axles, engineSize. The NegativeValueException is to be thrown in the “vehicle” constructor that is responsible for setting the field in question. The following shows how the constructor would be called: new NegativeValueException ) Fora similar constructor, see InvalidLengthException.java in Examples Polygons from this week’s lecture notes on Exceptions Page 2 of 8 roiect: Vehicles – Part 3 Page 3 of 8 Testing: Here is an example of a test method that checks to make sure a negative value for value in the constructor for Vehicle throws a NegativeValueException. Note that creating a Car invokes the constructor in Vehicle. You should consider adding test methods to check for negative values for the other numeric fields. @Test public void negativeValueExceptionTest) boolean thrown = false; try
car-new Car (“Jackson, Bo”, “2012 Toyota Camry”, -25000, false) Car catch (NegativeValueException e) thrown = true ; Assert.assertTrue (“Expected NegativeValueException to be thrown.”, thrown) /*or alternatively: / Assert.assertEquals(“Expected NegativeValueException to be thrown.”, true, thrown)
VehiclesPart3.java Requirements and Design: The VehiclesPart3 class has only a main method as described below. In addition to the specifications in Project 10, the main method should be modified to catch and UseTaxList class Page 4 of 8 Project: Vehicles – Part 3 Page 5 of 8 In Part 3, main reads in the file name from the command line as was done in Vehicles – Part 2, creates an instance of UseTaxList, and then calls the readVehicleFile method in the UseTaxList class to read in the data file. After successfully reading in the file, the main method then prints the summary, vehicle list by owner, vehicle list by use tax, and the list of excluded records. The main method should not include the throws FileNotFoundException in the declarationInstead, the main method should include a try-catch statement to catch o class. This exception will occur when an incorrect file name is passed to the readVehicleFile method_After this FileNotFoundException is caught, print the messages below and end *File not found Program ending. Also, if the user runs the program without a command line argument (e.g., args.length 0), main should print the following message and end. File name not provided by command line argument. Program ending.
public void readVehicleFile(String fileNameIn) throws FileNotFoundException { Scanner fileScan new Scanner (new File(fileNameIn) taxDistrict- fileScan.nextLine(); while (fileScan.hasNextO) bob fileScan.nextLine().trim(); String try = Scanner input – new Scanner(bob).useDelimiter(“;”); char vehicleTypeinput.next().toUpperCase().trim).charAt (0); String owner- input.next().trim(); String yMM-input.next().trim); String vinput.next().trim(); String aFinput.next().trimO; boolean altFuel false; if (aF.equals(“true”)) altFuel – true; double value – Double.parseDouble(v); switch (vehicleType) case “C’ Car c1- new Car(owner, yMM, value, altFuel); addVehicle(c1); break case T’: String tt input.next).trim); double tonsDouble.parseDouble(tt);
Truck t1new Truck (owner, yMM, value, altFuel, tons); addVehicle(t1); break case ‘S’ String tinput.next().trim(); String a -input.next().trim(); double tons2 = Double . parseDouble(t); int axle = Integer.parseInt(a); SemiTractorTrailer s1 new SemiTractorTrailer (owner, yMM, value, altFuel, tons2, axle); addVehicle(s1); break case ‘M’ String sinput.next().trim); int size Integer.parseInt(s); Motorcycle m1 -new Motorcycle (owner, yMM, value, altFuel, size); addVehicle(m1); break default addExcludedRecord(“Invalid Vehicle Category in: n” break bob); : J catch (NumberFormatException e) {
addExcludedRecord(e”in: In” bob); catch (NoSuchElementException e) addExcludedRecord (e in: In” bob); catch (NegativeValueException e addExcludedRecord (e in: In” bob);

Expert Answer


Answer to I need the below classes/tests. Thanks so much! Please let me know if there’s anything else you need. NegativeValueExcep… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *