Give answer according to fill in the blanks.
1.Define a class called Fraction . This class is used to represent a ratio of two integers.Include mutator methods that allow the user to set the numerator and the denominator. Also include a method that returns the value of numerator divided by denominator as a double . Include an additional method that outputs the value of the fraction reduced to lowest terms (e.g., instead of outputting 20/60, the method should output 1/3). This will require finding the greatest common divisor for the numerator and denominator, then dividing both by that number. Embed your class in a test program.
public class Fraction {
private int num1;
private int num2;
public void _____(1)_________{
this.num1 = num1;
}
public void setNum2(___(2)______){
this.num2 = num2;
}
//method two number divided,return double data
public double div(){
return (___________(3)_______________);
}
public String getFraction(){
int tmp1,tmp2;
tmp1 = this.num1;
tmp2 = this.num2;
//set remain from two number divided
int remain = _______(4)_____________;
//do loop,util the remain is 0 .then the common divisor is tmp2
_____(5)__________{
tmp1 = tmp2;
tmp2 = remain;
remain = ______(6)__________
}
//get the result of num1 divide common divisor
int a =_________(7)___________;
//get the result of num2 divide common divisor.
int b = ________(8)________;
return a+"/"+b;
}
public static void main(____(9)______) {
//get num from keyboard
Scanner scan = ______(10)_________;
int num1,num2;
double dividResult =0;
String fractionResult =””;
num1=num2=0;
num1 =_____(11)_______;
num2 = _____(12)__________;
Fraction fr =_______(13)____________;
Fr.setNum1(num1);
Fr.setNum2(num2);
dividResult =______(14)_______;
fractionResult =______(15)________;
System.out.println(fractionResult);
}
}
2.
Get the size from console and create an int array with that size, then assign a random value between [1,10] to each element of the array,finally output the array in 6 elements per line.
public static void main(____1____){
//declared the int array whith size 10
____2____ arr1 = new ____3____;
// use for loop ,set value to each element
for(____4____){
____5____ = (____6____)(Math.random()*10);
}
//output the element of array , 6 element one line
for(____7____){
if(____8____){
____9____;
}else{
System.out.print(____10____);
}
}
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Question 2:
Here a new java program with name "Main.java" is created, which contains following code.
Main.java :
public class Main //Java Class
{ //Main method
public static void main(String[] args) {
//declared the int array with size 10
int[] arr1 = new int[10];
// use for loop ,set value to each element
for(int i=0;i<10;i++){
arr1[i] = (int)(Math.random()*10);
}
//output the element of array , 6 element one line
for(int i=0;i<10;i++){
if(i==6){
System.out.println();//used for new line
System.out.print(arr1[i]+" ");
}else{
System.out.print(arr1[i]+" ");
}
}
}
}
======================================================
Output : Compile and Run above program to get the screen as shown below
Screen 1 :Main.java

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Give answer according to fill in the blanks. 1.Define a class called Fraction . This class...
Rational will be our parent class that I included to this post, Implement a sub-class MixedRational. This class should Implement not limited to: 1) a Constructor with a mathematically proper whole, numerator and denominator values as parameters. 2) You will override the: toString, add, subtract, multiply, and divide methods. You may need to implement some additional methods, enabling utilization of methods from rational. I have included a MixedRational class with the method headers that I used to meet these expectations....
I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...
Create a fraction class. This will have two attributes, a numerator and a denominator, both int. This class will have constructors accessors and mutators (for the attributes) a toString method which will allow us to print the fraction in the form 3/4 an Add method so we can add two fractions a subtract method (subtracts one fraction from the other) a multiply method (multiply two fractions) a divide method (divides one fraction by the other) DO NOT (for now) worry...
Design a class named Fraction. This class is used to represent a ratio of two integers, such as 6 / 9. Include accessors and mutators that allow the user to get and set the numerator and the denominator. Also include a member method that returns the value of the numerator divided by the denominator as double (for example, 0.666…). Include an additional member method that returns the value of the fraction reduced to lowest terms as string. For example, instead...
C++ I am using visual studio for it. Make a copy of the Rational class you created in the previous Lab. Modify the class. Replace all your mathematical, input, and output functions with overloaded operators. Overload the following 12 operators: + - * / < > = = ! = <= >= >> << In order to test your class in your main function, prompt the user for a numerator and a denominator for your first object. Repeat the prompt...
For the add method in Fraction class, fill the following blank. public Fraction add(Fraction f) { int num = numerator * f.getDenominator() + f.getNumerator() * denominator; int denom = denominator * f.getDenominator(); return ww new Fraction(num, denom) num/denom (double)num/(double)denom (int)num/denom
Add another public method called add to your Fraction class. This method adds another fraction to the ‘calling object’. Thus, the method will take a Fraction class object as a parameter, add this parameter fraction to the calling object (fraction), and return a Fraction object as a result. HINT: We can use cross multiplication to determine the numerator of the resultant Fraction. The denominator of the resultant Fraction is simply the multiplication of the denominators of the two other Fractions.Add...
This in in C# There are two classes, class Fraction and class FractionDemo The user needs to be able to input a value for the numerator and the denominator Create a Fraction class with private fields that hold a positive int numerator and a positive int denominator. In addition, create Properties for each field with the set mutator such that the numerator is greater than or equal to 0 and the denominator is greater than 0 (illegal values should be...
Redo Programming Exercise 7 of Chapter 7 so that your program handles exceptions such as division by zero and invalid input. Your program should print Denominator must be nonzero and reprompt for a valid denominator when 0 is entered for a denominator. Please specify what should go in the divisionByZero.h file and the changes made to main.cpp Please provide output. Thank you in advance! main.cpp so far #include <iostream> using namespace std; void addFractions(int num1, int num2, int den1, int...
Question 34 (2 points) For the add method in Fraction class, fill the following blank. public Fraction add(Fraction f) { int num = numerator * f.getDenominator() + f.getNumerator() * denominator; int denom = denominator * f.getDenominator: return } new Fraction(num, denom) O num/denom (double)num/(double)denom (int)num/denom Previous Page Next Page