Provide the missing code segment in the portion with the TO DO remark in the following sample code. The Book class involved in the code is provided below:
public class Book implements Comparable<Book> {
protected int pages;
public Book(){
pages = 1500;
}
public Book(int pages){
this.pages = pages;
}
public void setPages(int pages) {
this.pages = pages;
}
public int getPages() {
return pages;
}
public int compareTo(Book another) {
// if same then return 0
if(this.pages == another.pages)
return 0;
//if current has more than return 1 else return -1
else if (this.pages > another.pages)
return 1;
else
return -1;
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- upper limit. Define the class Random Integer in full.arrow_forwardpackage lab1; /** * A utility class containing several recursive methods * * <pre> * * For all methods in this API, you are forbidden to use any loops, * String or List based methods such as "contains", or methods that use regular expressions * </pre> * * */ public final class Lab1 { /** * This is empty by design, Lab class cannot be instantiated */ privateLab1(){ // empty by design } /** * Returns the product of a consecutive set of numbers from <code> start </code> * to <code> end </code>. * * @param start is an integer number * @param end is an integer number * @return the product of start * (start + 1) * ..*. + end * @pre. * <code> start </code> and <code> end </code> are small enough to let * this method return an int. This means the return value at most * requires 4 bytes and no overflow would happen. */ publicstaticintproduct(ints,inte){ if(s==e){ returne; }else{ returns*product(s+1,e); } }…arrow_forwardRuby-related coding: Need help in resolving the red-selected code parts of my practice problem, primarily dealing with case-sentitive, loops, and if-else statements. The ", :pending => true" needs to be removed, used for checking purposes. (Picture reference provided) Hangperson_game.rb class HangpersonGame# add the necessary class methods, attributes, etc. here# to make the tests in spec/hangperson_game_spec.rb pass.# Get a word from remote "random word" service# def initialize()# enddef initialize(word)@word = word@guesses = ""@wrong_guesses = ""enddef wordreturn @wordenddef guessesreturn @guessesenddef wrong_guessesreturn @wrong_guessesenddef guess(letter)if @word.include?(letter)@guesses += letterreturn true else@wrong_guesses += letterendenddef word_with_guessespartial_matches = ""@word.each_char do |w|partial_matches += "-"endreturn partial_matchesenddef check_win_or_loseif word_with_guesses.downcase == @word.downcasereturn :winelsif @wrong_guesses.length >= 7return…arrow_forward
- c) Draw a UML Diagram for the following source code. (CLO1, CLO2) public class MyCircle { double MyRadius= 0.0; MyCircle() { } MyÇircle(double newRadius) { MyRadius = newRadius; } double getArea() { return MyRadius * MyRadius * 3.14159;} public static void main(String[] args) { MyCircle C1 = new MyCircle(); C1 MyRadius = 2.0; MyCircle C2 = new MyCircle(); C2.MyRadius = 4.0; System.out.println(C1.getArea()); System.out println(C2,getArea(); } }arrow_forwardInstructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and…arrow_forwardin c++ codearrow_forward
- Java - Car Value (Classes)arrow_forwardg) Make a class Class (as in a class of students, not a class as in a class of objects) that stores several Student objects. Store a list of students in an attribute called students. The initializer method should initialize the class as an empty class (no students). Implement a method add_student() that takes an object of class Student and adds it to class. Implement method pass_rate() that determines the fraction of students that pass the class (have a grade of >= 6). python code!!arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education