Question

In: Computer Science

Define a class Fraction3YourName as follows, /** * Program Name: Fraction3YourName.java * Discussion: Fraction3Yourname class *...

Define a class Fraction3YourName as follows,

/**
* Program Name: Fraction3YourName.java
* Discussion: Fraction3Yourname class
* written By:
* Date: 2019/09/19
*/
public class Fraction3YourName {
private int sign;
private int num;
private int denom;
public Fraction3YourName() {
//sign = ;
//denom = ;
}
public Fraction3YourName(int n) {
//sign = ;
//num = n;
//denom = ;
}
public Fraction3YourName(int s, int n, int d) {
//sign = s;
//num = n;
//denom = d;
}
}

by java programming

Solutions

Expert Solution

/**
 * Program Name: Fraction3YourName.java
 * Discussion: Fraction3Yourname class
 * written By:
 * Date: 2019/09/19
 */
public class Fraction3YourName {
    private int sign;
    private int num;
    private int denom;

    public Fraction3YourName() {
        this(1, 0, 1);
    }

    public Fraction3YourName(int n) {
        this(1, n, 1);
    }

    public Fraction3YourName(int s, int n, int d) {
        sign = s;
        num = n;
        denom = d;
    }

    @Override
    public String toString() {
        String s = "";
        if (sign == 1) {
            s += "+";
        } else {
            s += "-";
        }
        s += num + "/" + denom;
        return s;
    }
}

class FractionTest {

    public static void main(String[] args) {
        Fraction3YourName f1 = new Fraction3YourName(1, 3, 7);
        System.out.println(f1);
        Fraction3YourName f2 = new Fraction3YourName(-1, 6, 7);
        System.out.println(f2);
    }
}


Related Solutions

Define a class Fraction3YourName as follows, /** * Program Name: Fraction3YourName.java * Discussion: Fraction3Yourname class *...
Define a class Fraction3YourName as follows, /** * Program Name: Fraction3YourName.java * Discussion: Fraction3Yourname class * written By: * Date: 2019/09/19 */ public class Fraction3YourName { private int sign; private int num; private int denom; public Fraction3YourName() { //sign = ; //denom = ; } public Fraction3YourName(int n) { //sign = ; //num = n; //denom = ; } public Fraction3YourName(int s, int n, int d) { //sign = s; //num = n; //denom = d; } } You are...
Define a class Fraction3YourName as follows, /** * Program Name: Fraction3YourName.java * Discussion: Fraction3Yourname class *...
Define a class Fraction3YourName as follows, /** * Program Name: Fraction3YourName.java * Discussion: Fraction3Yourname class * written By: * Date: 2019/09/19 */ public class Fraction3YourName { private int sign; private int num; private int denom; public Fraction3YourName() { //sign = ; //denom = ; } public Fraction3YourName(int n) { //sign = ; //num = n; //denom = ; } public Fraction3YourName(int s, int n, int d) { //sign = s; //num = n; //denom = d; } } You are...
Define a JAVA class ISP. The class consists of the name of the subscription plan and...
Define a JAVA class ISP. The class consists of the name of the subscription plan and a method that display the plan. Derive a class DPlan from ISP. The DPlan will charge RM10 per Mbps subscribe and RM0.20 per GB used. Derive a class MPlan from ISP. The MPlan will charge RM5 per Mbps subscribe and RM0.80 per GB used. Display the plan and select the best plan.
Create a class named GameCharacter to define an object as follows: The class should contain class...
Create a class named GameCharacter to define an object as follows: The class should contain class variables for charName (a string to store the character's name), charType (a string to store the character's type), charHealth (an int to store the character's health rating), and charScore (an int to store the character's current score). Provide a constructor with parameters for the name, type, health and score and include code to assign the received values to the four class variables. Provide a...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private member variables: description of type string and atime of type Time. The class Alarm also includes the following public member functions: 1. print to print out the alarm’s description and hour, minute, and second of the alarm time. 2. setDescription to accept a string argument and use it to set the description member variable. 3. setAtime to accept three integers (for hour, minute, and...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private...
A. Define and implement the class Alarm as follows: The class Alarm consists of two private member variables: description of type string and atime of type Time. The class Alarm also includes the following public member functions: 1. print to print out the alarm’s description and hour, minute, and second of the alarm time. 2. setDescription to accept a string argument and use it to set the description member variable. 3. setAtime to accept three integers (for hour, minute, and...
4) Define an abstract class Name Java class that implements interface Comparable   
4) Define an abstract class Name Java class that implements interface Comparable   
Create a Java program. The class name for the program should be 'EncryptText'. In the main...
Create a Java program. The class name for the program should be 'EncryptText'. In the main method you should perform the following: You should read a string from the keyboard using the Scanner class object. You should then encrypt the text by reading each character from the string and adding 1 to the character resulting in a shift of the letter entered. You should output the string entered and the resulting encrypted string. Pseudo flowchart for additional code to be...
Goals Understand class structure and encapsulation Description Define a class Product to hold the name and...
Goals Understand class structure and encapsulation Description Define a class Product to hold the name and price of items in a grocery store. Encapsulate the fields and provide getters and setters. Create an application for a grocery store to calculate the total bill for each customer. Such program will read a list of products purchased and the quantity of each item. Each line in the bill consists of: ProductName ProductPrice Quantity/Weight The list of items will be terminated by “end”...
Write a program that utilizes a Professor class. A professor has a first name, last name,...
Write a program that utilizes a Professor class. A professor has a first name, last name, affiliation, easiness grade, and a helpfulness grade. Grades range from 1 (lowest) to 5 (highest). The Professor class has two constructors. The first constructor initiates the object with just the first name, the last name, and the affiliation. The default value for easiness and helpfulness grade is 3. The second constructor initiates the object using the first name, the last name, the affiliation, and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT