Question

In: Computer Science

Plz, use NETBEANS 8.1 or 8.2 to solve it. Mention every answer to it's question Thank...

Plz, use NETBEANS 8.1 or 8.2 to solve it. Mention every answer to it's question

Thank u

Create a new Java Application to manage Linked Lists: (Note: Do not use java.util.LinkedList)

a) Create a Clock class

1. Add hour, minute, and second as attributes

2. Add a constructor and a toString() method

3. Implement the Comparable interface, and add a CompareTo() method

4. Add methods to get and set all attributes.

b) Add to MyLinkedList class the following methods:

1. Insert a node at the front of the list

2. Insert a Node in place, assuming that the list is ordered in ascending order.

3. Delete node in front

4. Delete last node

5. Method to return the size of the list

6. Method to find the node with the minimum value in the list – getMinimum()

c) Create a Test3 class to do the following in the main method:

1. Create a new List (call it clockList) of type MyLinkedList

2. Insert five Clock objects numbers to the list (not ordered).

3. Display all the clocks in the List

4. Sort the List and display it in both ascending and descending

5. Display the largest element in the list

6. Display the smallest element in the list

7. Display the size of the list

8. Search for a particular clock in the List by printing true if found or false.

9. Delete a clock from the front of the list

10. Delete a clock from the back of the list

11. Order the list in ascending order

12. Insert a new clock elements to its appropriate position in the List and display it

Solutions

Expert Solution


package listclasses;
public class Clock {
   int hour;
   int minute;
   int second;
  
   Clock(){
      
   }
   Clock(int hour,int minute,int second){
       this.hour=hour;
       this.minute=minute;
       this.second=second;
      
   }
  
   public String tostring(){
       return "hour is:"+hour+ "minute is:"+minute +"second is:"+second;
   }
}
class doublelinkedlist2 {
   doublelinkedlist2 privious;
   doublelinkedlist2 next;
   Clock c;
   public doublelinkedlist2(Clock c){
      
       this.c=c;
   }
public    doublelinkedlist2(doublelinkedlist2 privious,Clock c,doublelinkedlist2 next){
       this.privious=privious;
       this.c=c;
       this.next=next;
   }
      
   public String tostring(){
       return c+"";
   }
}


clockmain.java
package listclasses;
public class clockmain {
   static doublelinkedlist2 head;
   static int size=0;
   static {
       head=null;
       size=0;
      
   }
   public static void main(String[] args) {
       Clock c=new Clock(2,1,22);
       Clock c2=new Clock(3,2,23);
       Clock c3=new Clock(4,1,12);
       Clock c4=new Clock(5,55,32);
       Clock c5=new Clock(6,42,22);
   insertfront(c);
   insertfront(c2);
   insertfront(c3);
   insertfront(c4);
     
  
  
   insertrear(c5);
   display();
   removeanywhere(1);
   display();
     
  
   }
   public static void insertfront(Clock c){
       if(head==null){
           head=new doublelinkedlist2(null,c,null);
       }
           else{
               doublelinkedlist2 newlist=new doublelinkedlist2(null,c,head);
               head.privious=newlist;
           head=newlist;
           }
          
       size++;
   }
   public static void insertrear(Clock c){
       if(head==null)
           head=new doublelinkedlist2(null,c,null);
       else{
           doublelinkedlist2 current;
           current=head;
           while(current.next!=null){
               current=current.next;
           }
           doublelinkedlist2 newlist=new doublelinkedlist2(current,c,null);
           current.next=newlist;
       }
       size++;
      
   }
   public static void removefront(){
       if(head==null)
           return;
      
           head=head.next;
           head.privious=null;
           size--;
      
      
   }
   public static void removerrear(){
       if(head==null)
           return;
         
           if(head.next==null){
               head=null;
               size--;
               return;
           }
           doublelinkedlist2 curent=head;
           while(curent.next.next!=null){
               curent=curent.next;
           }
               curent.next=null;
               size--;
         
   }
   public static void removeanywhere(int index){
       if(head==null)return;
       if(index<1 ||index >size) return;
       int i=1;
       doublelinkedlist2 curent=head;
       while(i<index){
       curent=curent.next;
       i++;
       }
       if(curent.next==null){
           curent.privious.next=null;
           size--;
       }else if(curent.privious==null){
           curent=curent.next;
           curent.privious=null;
           head=curent;
           size--;
       }else{
           curent.privious.next=curent.next;
           curent.next.privious=curent.privious;
           size--;
       }
   }
   public static void insertanywhere(Clock c,int index){
       int i=1;
       if(head==null)
           return;
       if( index<1 || index>size)
           return;
       doublelinkedlist2 curent;
       curent=head;
       while(i<index){
           curent=curent.next;
           i++;
          
       }
       if(curent.privious==null){
           doublelinkedlist2 newlist=new doublelinkedlist2(null,c,curent);
           curent.privious=newlist;
           head=newlist;
           size++;
       }
       else
       {
           doublelinkedlist2 newlist=new doublelinkedlist2(curent.privious,c,curent);
           curent.privious.next=newlist;
           curent.privious=newlist;
           size++;
       }
      
   }
   public static void display(){
       while(head!=null){
           Clock c=(Clock)head.c;
           System.out.println(c.tostring());
           head=head.next;
       }
       System.out.println("size:"+size);
   }
  
  
   public static void isempty(){
       if(size<=0)
           System.out.println("empty");
       else
           System.out.println("not empty:");
      
   }
}
output:
j
hour is:5minute is:55second is:32
hour is:4minute is:1second is:12
hour is:3minute is:2second is:23
hour is:2minute is:1second is:22
hour is:6minute is:42second is:22
size:5


Related Solutions

(Information Accountinf System) how to solve computer frauds by Control techniques? NO HAND WRITER PLZ, Thank...
(Information Accountinf System) how to solve computer frauds by Control techniques? NO HAND WRITER PLZ, Thank you
Note: Use SPSS to solve the following questions. For every question Write the SPSS command and...
Note: Use SPSS to solve the following questions. For every question Write the SPSS command and then copy and paste the output page here (or in some cases the screenshot of the data view that shows the output). Can I Know also what is the sample file (in SPSS) that we work on? Question : (In this problem first find the probability by using SPSS and then calculate the number of trees manually by using the probabilities.) A certain variety...
Use the following information to answer Question 24 to Question 25: A poll was taken every...
Use the following information to answer Question 24 to Question 25: A poll was taken every month on how voters will vote on the next federal election. Here are the results of the poll: Sample Size Liberal Voters This Month 550 324 Last Month 700 406 24. (4 points) Develop a 95% confidence interval estimate for the difference between the proportions of voters who will vote for the Liberals in the two populations. Show your calculations. 25. (2 points) From...
Please answer every question thank you soo much!! 1)Ceratophyllum Echinatum -why are they consider Bryophytes? -...
Please answer every question thank you soo much!! 1)Ceratophyllum Echinatum -why are they consider Bryophytes? - how does ceratophyllum achieve fertilization/ pollonation? - is gametophyte dominant, sporophyte dominant, 50/50 or sporophyte only? 2) Lycophyta - why are they consider seedless vascular -how does ceratophyllum achieve fertilization/ pollonation? - is gametophyte dominant, sporophyte dominant, 50/50 or sporophyte only? 3) Parana Pine - why are they consider gymnosperms -how does ceratophyllum achieve fertilization/ pollonation? - is gametophyte dominant, sporophyte dominant, 50/50 or...
Each question has 6-7 parts, depending on the work. Please answer every part. Thank you. -...
Each question has 6-7 parts, depending on the work. Please answer every part. Thank you. - What is the formula for the Average Propensity to Consume (APC)? Group of answer choices consumption divided by income the change in consumption divided by a change in income income divided by consumption the change in income to a change in consumption None of the above - How does the size of the Marginal Propensity to Consume (MPC) affect the size of the multiplier...
Each question has 8-9 parts, depending on the work. Please answer every part. Thank you. -...
Each question has 8-9 parts, depending on the work. Please answer every part. Thank you. - The government spending multiplier is Group of answer choices the ratio of the change in the equilibrium level of output to a change in government spending the difference between the new and old levels of government spending. the ratio of the change in government spending to the change in the equilibrium level of output the difference between the old level of equilibrium output and...
Managerial Economics Question. (Please solve both A and B, and mention which one is A and...
Managerial Economics Question. (Please solve both A and B, and mention which one is A and B, thank you for working so much hard for me, I appreciate it.) 1. Royersford Kinitting Mills Ltd. sells a line of women's knit underwear. The firm now sells about 20,000 pairs a year at an average price of $10 each. Fixed costs amount to $60,000, and total variable costs equal $120,000. The production department has estimated that a 10 percent increase in output...
Each question has 6-7 parts, depending on the work. Please answer every part. Thank you. -Suppose...
Each question has 6-7 parts, depending on the work. Please answer every part. Thank you. -Suppose Government spending increases by $400 and Taxes increase by $400, and MPC = .80. Assuming that there is no crowding out, what will be the change in equilibrium income (Y*)? Group of answer choices - $400 NO CHANGE + $400 - $320 +$320 - Which of the following is NOT a Keynesian conjecture regarding consumption? Group of answer choices As income rises, APC falls....
Solve it by R Use the ‘cement’ dataset in ‘MASS’ package to answer the question. (1)...
Solve it by R Use the ‘cement’ dataset in ‘MASS’ package to answer the question. (1) Conduct the multiple linear regression, regress y value on x1, x2, x3 and x4 (without intercept). Report the estimated coefficients. Which predictor variables have strong linear relationship with response variable y at significance level 0.05? (2) What is the adjusted R square of your regression? What is the interquartile range (IQR) of the residuals from your regression? (3) Conduct a best subset regression (with...
this a continuation of my previous question. answer with Java programming language and Netbeans idk 1,...
this a continuation of my previous question. answer with Java programming language and Netbeans idk 1, 2, 3, 4) CODE class Device { private String serialNumber, color, manufacturer; private double outputPower; public Device () { serialNumber = ""; color = ""; manufacturer = ""; outputPower = 0.0; } public Device(String serialNumber, String color, String manufacturer, double outputPower) { this.serialNumber = serialNumber; this.color = color; this.manufacturer = manufacturer; this.outputPower = outputPower; } public String getSerialNumber() { return serialNumber; } public void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT