Please Use Java. Thank you!

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please Use Java. Thank you!

Post by answerhappygod »

Please Use Java. Thank you!
Please Use Java Thank You 1
Please Use Java Thank You 1 (133.63 KiB) Viewed 26 times
Please Use Java Thank You 2
Please Use Java Thank You 2 (48.76 KiB) Viewed 26 times
Purpose: A class is a blueprint or prototype from which objects/instances are created. It includes fields or methods common to all objects of the same blueprint/class. Generally, a class declaration has components: class header, constructors, methods such as getter/setter, and so on. The constructors are used for initializing new instances. Fields are variables representing the state of the class and its objects. The methods are used to implement the behavior of the class and its objects. In this assignment, we will practice how to define classes and create objects. Once a class is available, 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. Methods can use this class as parameter type or return type. Program #1: Add the divide method to take another Fraction as the parameter and return a new Fraction, the division of the current Fraction and the Fraction in the parameter. (public Fraction divide (Fraction f)). Add scaleup and scaledown methods to the Fraction class. The scaleup method will take a factor as the parameter and multiply the numerator by the factor. The scaledown method will take a factor as the parameter and multiply the denominator by the factor. Add a scale method that will have two parameters: factor and flag. The flag is boolean. If the flag is true, scale up the Fraction; otherwise, scale down the Fraction. Both scaledown and scale methods must check if the factor is 0. If it is 0, a warning message is printed, and no scaling is operated. Add two more constructors. One of the constructors will have no parameters; it initializes the Fraction to 0/1. The other constructor will have one parameter representing the numerator of the Fraction; the denominator of the Fraction will be 1. Write a program named Fraction Scale that prompts the user of a fraction and a scale factor. Here is what the user will see on the screen: This program performs the scaling operations on a fraction. Enter a fraction: 3/7 Scale up or down (1: up, 0: down): 1 Enter a scale factor: 2 Scaled Fraction is: 6/7

public class Fraction { // Instance variables } You can assume that the user always enters two integers separated by a slash (/) for the faction. However, the user may enter any number of spaces before and after each integer. private int numerator; // Numerator of fraction private int denominator; // Denominator of fraction // Constructors public Fraction(int num, int denom) { numerator = num; denominator = denom; } // Instance methods public int getNumerator() { return numerator; } public int getDenominator() { return denominator; } public Fraction add(Fraction f) { int num = numerator * f.denominator + f.numerator * denominator; } int denom = denominator * f.denominator; return new Fraction (num, denom);
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply