1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NemiM [27]
3 years ago
11

Write a program that lets the user perform arithmetic operations on fractions. Fractions are of the form a/b, in which a and b a

re integers and b is not equal to 0. Your program must be menu driven, allowing the user to select the operation ( , -, *, or /) and input the numerator and the denominator of each fraction. Furthermore, your program must consist of at least the following function
menu: This function informs the user about the program's purpose, explains how to enter data, how to quit and allows the user to select the operation.
addFractions: This function takes as input four integers representing the numerators and denominators of two fractions, adds the fractions, and returns the numerator and denominator of the result.
subtractFractions: This function takes as input four integers representing the numerators and denominators of two fractions, subtracts the fractions, and returns the numerator and denominator of the result.
multiplyFractions: This function takes as input four integers representing the numerators and denominators of two fractions, multiplies the fractions, and returns the numerator and denominator of the result.
divideFractions: This function takes as input four integers representing the numerators and denominators of two fractions, divides the fractions, and returns the numerator and denominator of the result.

Here are some sample outputs of the program:

3 / 4 +2 / 5 = 23 / 20
2 / 3 * 3 / 5 = 2 / 5
Computers and Technology
1 answer:
serious [3.7K]3 years ago
8 0

Answer:

Explanation:

The following code is written in Java, It asks the user to enter the numerator and denominator for both fraction 1 and 2. Then it prompts the user with a menu to choose the desired operation. The choice is passed into a switch statement and calls the correct function.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int num1, num2, den1, den2;

       System.out.println("Enter numerator for fraction 1: ");

       num1 = in.nextInt();

       System.out.println("Enter denominator for fraction 1: ");

       den1 = in.nextInt();

       System.out.println("Enter numerator for fraction 2: ");

       num2 = in.nextInt();

       System.out.println("Enter denominator for fraction 2: ");

       den2 = in.nextInt();

       System.out.println("Menu:");

       System.out.println("+ = add fractions");

       System.out.println("- = subtract fractions");

       System.out.println("/ = divide fractions");

       System.out.println("* = multiply fractions");

       String answer = in.next();

       switch (answer.charAt(0)) {

           case '+': add(num1, den1, num2, den2); break;

           case '-': subtract(num1, den1, num2, den2); break;

           case '*': multiply(num1, den1, num2, den2); break;

           case '/': divide(num1, den1, num2, den2); break;

       }

   }

   public static void add(int num1, int den1, int num2, int den2) {

       int num3 = (num1 * den2) + (num2 * den1);

       int den3 = den1 * den2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

   public static void subtract(int num1, int den1, int num2, int den2) {

       int num3 = (num1 * den2) - (num2 * den1);

       int den3 = den1 * den2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

   public static void divide(int num1, int den1, int num2, int den2) {

       int num3 = num1 * den2;

       int den3 = den1 * num2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

   public static void multiply(int num1, int den1, int num2, int den2) {

       int num3 = num1 * num2;

       int den3 = den1 * den2;

       System.out.println("New Fraction: " + num3 + " / " + den3);

   }

}

You might be interested in
You would like to put the data in order by product number. What should you do?
Dafna11 [192]

If someone wants to put data in order (ascending or descending) they should sort the data.

c. Sort

<u>Explanation:</u>

Sorting is the process of arranging the data on the basis of some property or attribute. Using the find command, conducting a query, and mapping the data would not help.

There are various sorting algorithms like the bubble sort, selection sort, insertion sort, quick sort, and merge sort. Out of all the attributes, one or a combination of attributes can be selected to serve as the basis for sorting.

8 0
2 years ago
Convert the following decimal number to its equivalent binary ,octal,hexadecimal 1920​
Serhud [2]

Answer:

0b11110000000 is binary

0o3600 is in octal

0x780 in hexa dec.

Explanation:its a bit complitcated to explain sorry bro!

3 0
3 years ago
What did Adam and Eve look like?
Nata [24]
No one could possibly know, unfortunately.
6 0
2 years ago
Read 2 more answers
How do you think weather can affect sailing?<br><br>What would be good sailing weather?​
N76 [4]

Answer:

Weather can affect sailing because if its raining it can sink it also if theres a storm. Good weather that would be good to sail in is if its a little windy because if its just sunny and not windy it wont move. ps you can copy it if u want idc

6 0
3 years ago
Write a statement to create a Google Guava Multimap instance which contains student ids as keys and the associated values are st
Sergeu [11.5K]

Answer: provided in the explanation section

Explanation:

Note: take note for indentation so as to prevent error.

So we import com.google.common.collect.Multimap;

import java.util.Collection;

import java.util.Map;

class Main {

   public static void main(String[] args) {

       // key as studentId and List of Profile as value.

       Multimap<String,Profile> multimap = ArrayListMultimap.create();

       multimap.put("id1", new ExamProfile("examStudentId1"));

       multimap.put("id1", new ELearningProfile("userId1"));

       multimap.put("id2", new ExamProfile("examStudentId2"));

       multimap.put("id2", new ELearningProfile("userId2"));

       // print the data now.

       for (Map.Entry<String, Collection<Profile>> entry : multimap.entrySet()) {

           String key = entry.getKey();

           Collection<String> value =  multimap.get(key);

           System.out.println(key + ":" + value);

       }

   }

}

// assuming String as the studentId.

// assuming Profile as the interface. And Profile can multiple implementations that would be

// specific to student.

interface Profile {

}

class ExamProfile implements Profile {

   private String examStudentId;

   public ExamProfile(String examStudentId) {

       this.examStudentId = examStudentId;

   }

}

class ELearningProfile implements Profile {

   private String userId;

   public ELearningProfile(String userId) {

       this.userId = userId;

   }

}

This code is able to iterate through all entries in the Google Guava multimap and display all the students name in the associated students profile.

8 0
3 years ago
Other questions:
  • considering that two variables counters and accumulators are important in loop design. What would be their purpose?
    9·1 answer
  • How do humans feel about being abducted?
    12·2 answers
  • Jason works as an accountant in a department store. He needs to keep a daily record of all the invoices issued by the store. Whi
    13·2 answers
  • Nick is working on a new graphic for one of his company’s clients and is having an issue with the color on his screen. The clien
    8·1 answer
  • Whic flag has a special role in debuging
    6·1 answer
  • What is the best way to locate where my C program gets into an infinite loop
    5·1 answer
  • A domain name is used to: *
    15·1 answer
  • Which of the following tools enables a production mixer to sync audio and video?
    7·1 answer
  • Please please help I don’t understand
    6·1 answer
  • A construction-based client would like to develop an application that can analyze an image of machinery and overlay information
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!