Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can we use BufferReader instead of Scanner? . please change it to BufferReader 1

ID: 3540483 • Letter: C

Question

   can we use BufferReader instead of Scanner? . please change it to BufferReader

1)  Inheritance: You must determine what (if anything) should be abstract, what should be inherited, and what should be overridden
a) Create class Shape. The class should have a variable for the shape's area and perimeter. There should also be methods to "get" these variables. Also create a method called calculate, whose purpose is to calculate the appropriate values for both of these variable and then set them (do not create a "set" method for these variables).
b) Create classes Circle, Rectangle, and RightTriangle that each will inherit from class Shape, and class Square, decide if class Square should inherit from class Rectangle or class Shape. Include whatever additional variables that are appropriate to each of these shapes.
Create method bodies for any abstract methods that might have been inherited.
c) The constructors for these objects must take in some int value (which will determine the size of the shape). If that parameter (or parameters) are not positive (zero or negative), throw an IllegalNegativeArgumentException. (see part d). The String passed to the constructor of the exception class should be a meaningful description of the context in which the exception is being thrown.
d) Create class IllegalNegativeArgumentException, which should inherit from IllegalArgumentException.
e) Create method resetDimensions in each of these classes (hint, rely on inheritance). The method does not take in any parameters. It should generate a JOptionPane to ask the user what the new value (or values) should be for the variable (or variables) that determine the size of this object. Put the line of code that would convert the string into an int in a try/catch block to catch for a NumberFormatException. In the same try block, throw an IllegalNegativeArgumentExcpetion if the value is not positive. Catch here for this Exception too, but not in the same catch block that the NumberFormatException was caught. If either Exception is thrown, do not change the value (or values) of the variables. Do not ask the user to input again a new value. A JOptionPane should be created to inform the user of the type of error made in his input, and that no changes were made.
f) Create another class that has only a main method, call this class Assignment5. This method should create an array of type Shape, with room for 10 shape objects. Fill the array with a variety (at least one of each of the 4) of Shape objects. Then, loop through the array, calling calculate on each of the shape objects. Rely on polymorphism, do not determine what each object type is. Output (to the console or with a JOptionPane) the average area of all 10 shapes.   you did not create class square in part b .

Explanation / Answer

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.io.File;


public class TextReader {

private static void readFile(String fileName) {

try {

File file = new File(fileName);

FileReader reader = new FileReader(file);

BufferedReader in = new BufferedReader(reader);

String string;

while ((string = in.readLine()) != null) {

System.out.println(string);

}

in.close();

} catch (IOException e) {

e.printStackTrace();

}

}


public static void main(String[] args) {

if (args.length != 1) {

System.err.println("usage: java TextReader "

+ "file location");

System.exit(0);

}

readFile(args[0]);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote