CSC1302 Lab 11- Advanced Java Array of Objects Solved

29.99 $

Description

5/5 - (1 vote)

Purpose:
Instance variables belong to the instance of a class, i.e., an object. Every object of that class has its own copy of that instance variable. Changes made to a particular instance variable donot reflect in other instances of that class.
Class variables are known as static variables. There is only one copy of that variable that is shared with all instances of that class. If changes are made to that variable, all other instances will see the change.
Instance methods belong to the object of the class, can only be called after an object of its class is created. Static/class methods can be called without creating an object of class. They are referenced by the class name itself or reference to the Object of that class.
In this assignment, we will practice how to use multiple classes and array of objects as well as class variables/methods. Once a class is available, it’s like we have a new data type. Variables can be defined with a type of this class and can refer to an object of this class. An array type can be user-defined class. Methods can use this class as parameter type or return type.
Task:
Write a class called Fraction with the following instance variables:
1) int numerator;
2) int denominator;
Please write the correct constructor and corresponding getter and setter. Note that, both numerator and denominator are private.
Write a Client class called MultiplyClient. In the main class, please instantiate an instance of Fraction[] FractionArray whose length is last-digit of PantherID + 3.
– For each element in FractionArray, please randomly create the fractions whose numerator and denominator are randomly set in the range of [1,10].
– Apply the FractionMultiply method to calculate the product of each adjacent pair of elements in FractionArray (e.g., FractionArray[0] and FractionArray[1]; FractionArray[1] and FractionArray[2])
– Print out the results in console. (Do not need to simplify the result; 24 is fine as the output).
Please implement the following method in the client class:
FractionMultiply(Fraction Example1, Fraction Example2): Return the result of Example1 * Example2 as a Fraction.
Criteria:
1. Upload all of the .java and the .class files to the CSc1302 dropbox on http:// icollege.gsu.edu.
3. Please comment the important lines in the .java file as shown in the template. The important lines including but not limited to i) variables, ii) for-loop, iii) while-loop, iv) if-else statement, iv) methods. Please use your own words to describe what is your purpose to write this line. A .java file without comment will be graded under a 40% penalty.
4. Make sure that both the .java and .class files are named and uploaded to icollege correctly. If any special package is used in the program, be sure to upload the package too. Should you use any other subdirectory (whatsoever) your program would not be graded, and you will receive a 0 (zero).
5. No copying allowed. If it is found that students copy from each other, all of these programs will get 0.

  • lab-11-hwm5nv.zip