Question

write the following code in java thank you and if you can, could you please write...

write the following code in java thank you and if you can, could you please write the code in replit and sent me a link to it replit is basically like a online compiler and you can write java code on it thank you

The first part is to implement one of the questions from your examination.

/*

A Range objects represents an integer range, such as

1-10 or 50701-50799. The lower and upper bounds of

a Range are given at the time the object is created.

*/

public interface Range {

    public boolean contains( int value );

    // returns true if v is ≥ lower bound and ≤ upper bound,

    // and false otherwise

    public boolean overlaps( Range other );

    // returns true if the receiver contains at least

    // one value in common with other, and false otherwise

    public int size();

    // returns the number of integers in the range

    public boolean isEquals( Range );

    // Returns if the passed in Range is equal to the range in the

    //class

}

public class PriceRange implements Range {

               // your implementations go here

}

When you create your classes(es) you should create then under source directories:

            src/main/java

            src/test/java

0 0
Add a comment Improve this question Transcribed image text
Answer #1
package HomeworkLib1;
public class PriceRange implements Range{
        private int lower;
        private int upper;
        int getLower() { return this.lower; }
        int getUpper() { return this.upper; }
        void setLower(int x) { lower = x; }
        void setUpper(int x) { upper = x; }
        public int size() {
                return this.getUpper()-this.getLower();
        }
        public boolean contains( int value ) {
                return (value>=this.getLower() && value<=this.getUpper())?true:false;
        }
        public boolean overlaps(Range other) {
                return (this.contains(((PriceRange)other).getLower()))?true:false;
                                                //If other's lower value is contained inside receivers range, then it overlaps
        }
        public boolean isEquals(Range o) {
                boolean flag = false;
                if(this.getLower()==((PriceRange)o).getLower() && this.getUpper()==((PriceRange)o).getUpper())
                        flag = true;
                return flag;
        }
        public static void main(String[] args) {
                PriceRange p1, p2, p3;
                p1 = new PriceRange();
                p2 = new PriceRange();
                p3 = new PriceRange();
                p1.setLower(0);
                p1.setUpper(299);
                p2.setLower(150);
                p2.setUpper(650);
                p3.setLower(0);
                p3.setUpper(299);
                System.out.println("Range 1 - " + p1.getLower() + "-" + p1.getUpper());
                System.out.println("Range 2 - " + p2.getLower() + "-" + p2.getUpper());
                System.out.println("Range 3 - " + p3.getLower() + "-" + p3.getUpper());
                System.out.println("Does Range 1 contains 146? " + p1.contains(100));
                System.out.println("Size of Range 2 - " + p2.size());
                System.out.println("Does Range 2 overlaps Range 1? " + p1.overlaps(p2));
                System.out.println("Are Range 1  and Range 3 equal? " + p1.isEquals(p3));
        }
}
D Range.java PriceRange java 3 1 package HomeworkLibl; 2 public class PriceRange implements Range( private int lower; private int u
Add a comment
Know the answer?
Add Answer to:
write the following code in java thank you and if you can, could you please write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The first part is to implement one of the questions from your examination. /* A Range...

    The first part is to implement one of the questions from your examination. /* A Range objects represents an integer range, such as 1-10 or 50701-50799. The lower and upper bounds of a Range are given at the time the object is created. */ public interface Range {     public boolean contains( int value );     // returns true if v is ≥ lower bound and ≤ upper bound,     // and false otherwise     public boolean overlaps( Range other...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...

  • Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file...

    Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file with the appropriate name. public class BasicJava4 { Add four methods to the class that return a default value. public static boolean isAlphabetic(char aChar) public static int round(double num) public static boolean useSameChars(String str1, String str2) public static int reverse(int num) Implement the methods. public static boolean isAlphabetic(char aChar): Returns true if the argument is an alphabetic character, return false otherwise. Do NOT use...

  • I'm having trouble making a code for this problem, my class is working with java in...

    I'm having trouble making a code for this problem, my class is working with java in while loops and for loops. Write a method that returns true if an integer parameter n is a perfect number, false otherwise. (recall a perfect number is a number whose sum of its proper factors is equal to itself) (Precondition: n >= 1 .. means you are to presume n is positive) : EXAMPLE: 6 is a perfect number 1 2 3 equals 6...

  • [Java] PLEASE FIX MY CODE I think I'm thinking in wrong way. I'm not sure what...

    [Java] PLEASE FIX MY CODE I think I'm thinking in wrong way. I'm not sure what is wrong with my code. Here'e the problem: Write a class SemiCircle that represents the northern half of a circle in 2D space. A SemiCircle has center coordinates and a radius. Define a constructor: public SemiCircle(int centerX, int centerY, int theRadius) Implement the following methods: public boolean contains(int otherX, int otherY) returns true if the point given by the coordinates is inside the SemiCircle....

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • The following is for java programming. the classes money date and array list are so I are are pre...

    The following is for java programming. the classes money date and array list are so I are are pre made to help with the coding so you can resuse them where applicable Question 3. (10 marks) Here are three incomplete Java classes that model students, staff, and faculty members at a university class Student [ private String lastName; private String firstName; private Address address; private String degreeProgram; private IDNumber studentNumber; // Constructors and methods omitted. class Staff private String lastName;...

  • can i please get help on this? i don't know how to do it and I'm...

    can i please get help on this? i don't know how to do it and I'm so confused. This is in java. This is what I need to do. Thank you so much. In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set contains no duplicates). This ADT must be implemented as a singly linked list of integers (with no tail reference and no dummy head node) , but...

  • it is a java question, thank you very much!! Question 2 20 marks) Write a class...

    it is a java question, thank you very much!! Question 2 20 marks) Write a class named GeoCoordinate that retains the longitude and latitude of an object on earth. Both longi- tude and latitude are represented as double values that must be in the range [-90.0, 90.00. The class has the following constructors: GeoCoordinate0, which initializes the latitude to 0.0 (the equator, the longitude to 0.0 (the prime meridian) GeoCoordinate(double longitude, double latitude): initializes the longitude and latitudes to values...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT