Access over 35 million academic & study documents

6 (10 points) Consider the tollowing code that checks to see if an a

Content type
User Generated
Rating
Showing Page:
1/3
6. (10 points) Consider the tollowing code that checks to
see if an array is sorted. Create anonymous functions for
each of the following cases that responds with true if the
first argument is less than the second. Finally show how to
invoke isSorted to answer the requests that follow: (a)
Compare two fractions (cach a struct with numerator and
denominator) to see if the first is less than the second. The
array of fractions to verify is called fractions. (b) Compare
two times according to their occurrence in the day. A time
is a struct with three numeric fields hour, min and sec. The
array of times to verify is called times. function s-
isSorted(a, cFun) s true; for ii . 2:length(a) if cFun (a(ii-1),
a(i)) sfalse; end end
Solution
import java.util.Scanner; import
com.gigal.fractionexercise.helper.Messages; import
com.gigal.fractionexercise.model.Division; import
com.gigal.fractionexercise.model.Fraction; import
com.gigal.fractionexercise.model.Multiplication; import
com.gigal.fractionexercise.model.Subtraction; import
com.gigal.fractionexercise.model.Addition; public class
FractionsApp { private static Scanner keyboard = new
Scanner(System.in); public static void main(String args[])
{ Fraction fraction1 = new Fraction(); // first fraction
Fraction fraction2 = new Fraction(); // second fraction //

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
Display application header Messages.displayHeader();
// get user inputs for fraction one and validate them do {
System.out.println(\"Enter values for fration one\");
Messages.insertNumerator(); try {
fraction1.setNumerator(keyboard.nextInt()); // get user
input } catch (Exception e) {
Messages.inputError(e); // display error return;
} Messages.inputDenominator(); try {
fraction1.setDenominator(keyboard.nextInt()); // get user
input } catch (Exception e) {
Messages.inputError(e); return; } if
(fraction1.getDenominator() == 0) { // check for x/0 error
Messages.DenominatorCannotBeZero(); } } while
(fraction1.getDenominator() == 0); // Display fraction
one System.out.print(\"Fraction one : \");
fraction1.display(); Messages.newLine(); // get user
inputs for fraction two and validate them do {
System.out.println(\"Enter values for fration two\");
Messages.insertNumerator(); try {
fraction2.setNumerator(keyboard.nextInt()); // get user
input } catch (Exception e) {
Messages.inputError(e); return; }
Messages.inputDenominator(); try {
fraction2.setDenominator(keyboard.nextInt()); // get user
input } catch (Exception e) {

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
6. (10 points) Consider the tollowing code that checks to see if an array is sorted. Create anonymous functions for each of the following cases that responds with true if the first argument is less than the second. Finally show how to invoke isSorted to answer the requests that follow: (a) Compare two fractions (cach a struct with numerator and denominator) to see if the first is less than the second. The array of fractions to verify is called fractions. (b) Compare two times according to their occurrence in the day. A time is a struct with three numeric fields hour, min and sec. The array of times to verify is called times. function s isSorted(a, cFun) s true; for ii . 2:length(a) if cFun (a(ii -1), a(i)) sfalse; end end Solution import java.util.Scanner; import com.gigal.fractionexercise.helper.Messages; import com.gigal.fractionexercise.model.Division; import com.gigal.fractionexerc ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Very useful material for studying!

Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Similar Documents