Question: JAVA: Two integers, babies 1 and babies 2 , are read from input as the number of babies for two rabbits. headObj has the default
JAVA: Two integers, babies and babies are read from input as the number of babies for two rabbits. headObj has the default value of Create a new node firstRabbit with integer babies and insert firstRabbit after headObj. Then, create a second node secondRabbit with integer babies and insert secondRabbit after firstRabbit.
Ex: If the input is then the output is:
You will need to create two source files:
import java.util.Scanner;
public class RabbitLinkedList
public static void mainString args
Scanner scnr new ScannerSystemin;
RabbitNode headObj;
RabbitNode firstRabbit;
RabbitNode secondRabbit;
RabbitNode currRabbit;
int babies;
int babies;
babies scnrnextInt;
babies scnrnextInt;
headObj new RabbitNode;
Your code goes here
currRabbit headObj;
while currRabbit null
currRabbit.printNodeData;
currRabbit currRabbit.getNext;
public class RabbitNode
private int babiesVal;
private RabbitNode nextNodeRef;
public RabbitNodeint babiesInit
this.babiesVal babiesInit;
this.nextNodeRef null;
public void insertAfterRabbitNode nodeLoc
RabbitNode tmpNext;
tmpNext this.nextNodeRef;
this.nextNodeRef nodeLoc;
nodeLoc.nextNodeRef tmpNext;
public RabbitNode getNext
return this.nextNodeRef;
public void printNodeData
System.out.printlnthisbabiesVal;
Given e code segments above, fill in the missing lines of code for the RabbitLinkedList file.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
