Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this code in Java, and add comments so I know what the lines are. I will be sure to give you a thumbs

Please do this code in Java, and add comments so I know what the lines are. I will be sure to give you a thumbs up. Thank You.
image text in transcribed
image text in transcribed
image text in transcribed
1. Start NetBeans. 2. Create a new project called Lab4. 3. Create a Java main class file using the class name Yourlastnamel.ab4 with your actual last name. 4. Modify the Java Interface template: (a) In the Tools menu, select Templates. (b) In the dialog box that comes up, open the Java folder, select Java Interface and click the Open in Editor button. (c) A new file should open up containing the following text: => != ""> package \$\{package\}; $;name) i i (d) Delete the first four lines and after @author replace the text $ \{user\} with your first and last name. (e) In the File menu select Save. You can also click on the Save All icon to save your files. (f) Close the Java Interface file by clicking the X on the tab. 5. Create a Java interface file for an interface called Convertible. (g) In the File menu select New File... (h) Under Categories: make sure that Java is selected. (i) Under File Types: make sure that Java Interface is selected. (j) Click Next. (k) For Class Name: type Convertible. (I) For Package: select csci2011.lab4. (m) Click Finish. (n) A text editor window should pop up with the following source code (except with your actual name): package csci2011.lab4; (a)author */ public interface Newlnterface \& 6. Add method headers to the Comparable interface. (o) Add a method header for a method called int Value that takes no arguments and returns a value of type int. (p) Add a method header for a method called doubleValue that takes no arguments and returns a value of type double. 7. Create a Java class file for a Number class. 8. Implement the Number class as an abstract class. (q) Add a method header for a method called add that takes a Number and returns a Number. (r) Add a method header for a method called negate that has no parameters and returns a Number (s) Add a method called subtract that takes a Number and returns the restult of subtracting the parameter from the Number the method is called on using the following formula: (t) Add a method header for a method called multiply that takes a Number and returns a Number. 9. Create a Java class file for a Fractional class. 10. Implement the Fractional class as an abstract class. (u) The Fractional class should extend the Number class. (v) Add a method header for a method called reciprocal that has no parameters and returns a Fractional. (w) Add a method called divide that takes a Fractional and returns the result of dividing the parameter from the Fractional the method is called on using the following formula: 11. Create a Java class file for a Rational class. 12. Implement the Rational class. Make sure to test each method in your main class as you are implementing it. You should implement all of the methods as stubs first to make sure the code compiles. (x) The Rational class should extend the Fractional class and implement the Comparable and Convertible interfaces. (y) Add private instance variables for a numerator and a denominator, both integers. (z) Add a constructor that takes two integers, a numerator and a denominator, and does the following: - If the denominator is zero, display an error message and exit the program. - If the denominator is less than zero, initialize the numerator and denominator private instance variables to the negation of the numerator and denominator parameters. This guarantees that the denominator is always greater than zero. - If the denominator is greater than zero, initialize the private instance variables using the corresponding parameters. (aa) Implement the add, multiply, and negate methods from the Number class using the following formulas: (ab) You will need to cast the parameters for add and multiply to Rational objects before using them. (ac) Implement the reciprocal method from the Fractional class using the following formula: (aa) Implement the add, multiply, and negate methods from the Number class using the following formulas: (ab) You will need to cast the parameters for add and multiply to Rational objects before using them. (ac) Implement the reciprocal method from the Fractional class using the following formula: (ad) If the numerator is zero, the method should display an error message and exit the program. (ae) Implement the compareTo method from the Comparable using the following information. - If then, so . - If then, so . - If then, so . (af) Implement the intValue and doubleValue methods from the Convertible interface using integer division and floating point division respectively

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

For s Answered: 1 week ago

Answered: 1 week ago

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

4.4 Summarize the components of a job description.

Answered: 1 week ago