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...
Question1: Define a class Human that contains: - The data fields "first name" and "last name"...
Question1: Define a class Human that contains: - The data fields "first name" and "last name" - A constructor that sets the first and last name to the instance variables. Create also a no-argument constructor - A getName() method which prints the first and last name Define the class Student which inherits Human and contains: - Private data field "mark" of type integer and a constructor which calls the superclass constructor Define the class Worker which inherits Human and contains:...
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”...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT