Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java applet program that implements class IntSet and class SummableSet.

ID: 3699448 • Letter: W

Question

Write a Java applet program that implements class IntSet and class SummableSet. Class IntSet should hold the ability to add a number to the set, delete a number from the set, clear the set, and search for numbers in a set. Class SummableSet should hold the ability to retrieve the sum of the set of numbers that is input by the user. The program should therefore have 5 functioning buttons, an TextField for input, and a TextArea to display the results.

The program is also supposed to handle some exceptions, e.g. when a user is trying to delete an element which is not in the set. To implement this program, you need to use a data structure to store the set. You can choose to store the set of integers using your own implemented binary search tree or using a built-in data structure, e.g. Vector, from java.util library. Be informed that you are supposed to implement this program in such a way that class SummableSet inherits from class IntSet.

Explanation / Answer

=>The Insets class provides a way to encapsulate the layout margins of the four different sides of a container. The class helps in laying out containers. The Container can retrieve their values through the getInsets() method, then analyze the settings to position components.

Insets Methods:

public int top

This variable contains the border width in pixels for the top of a container.

public int bottom

This variable contains the border width in pixels for the bottom of a container.

public int left

This variable contains the border width in pixels for the left edge of a container.

public int right

This variable contains the border width in pixels for the right edge of a container

Constructors

public Insets (int top, int left, int bottom, int right)

The constructor creates an Insets object with top, left, bottom, and right being the size of the insets in pixels. If this object was the return object from the getInsets() method of a container, these values represent the size of a border inside that container.

Miscellaneous methods

public Object clone ()

The clone() method creates a clone of the Insets so the same Insets object can be associated with multiple containers.

public boolean equals(Object object)  

The equals() method defines equality for insets. Two Insets objects are equal if the four settings for the different values are equal.

public String toString ()

The toString() method of Insets returns the current settings. Using the new Insets (10, 20, 30, 40) constructor, the results would be:

porgram:

======

import java.awt.*;
import java.applet.*;


public class InsetsDemo extends Applet
{
  
public void init()
{
setBackground(Color.cyan);
setLayout(new BorderLayout());
add(new Button("RMI"),BorderLayout.NORTH);
add(new Button("SERVLET"),BorderLayout.EAST);
add(new Button("JDBC"),BorderLayout.SOUTH);
add(new Button("BEANS"),BorderLayout.WEST);
add(new Button("JAVA"),BorderLayout.CENTER);
}


public Insets getInsets()
{
return new Insets(10,20,10,20);
}
}
/*
<applet code=”InsetsDemo.class” width=300 height=200>

here we give example of sum of two numbers

import java.awt.*;  

import java.awt.event.*;  

import java.applet.*;  

?public class SummableSet extends Applet implements ActionListener  

{ TextField t1 = new TextField(10);

    TextField t2 = new TextField(10);  

    TextField t3 = new TextField(10);  

    Label l1 = new Label("FIRST NO=:");  

    Label l2 = new Label("SECOND NO:");  

    Label l3 = new Label("SUM:");  

    Button b = new Button("ADD");  

    public void init()  

    {  

        t1.setForeground(Color = Red);  

        add(l1);  

        add(t1);  

        add(l2);  

        add(t2);  

        add(l3);  

        add(t3);  

add(b);  

        b.addActionListener(this);  

    }

public void actionPerformed(ActionEvent e)

    {  

if (e.getSource() == b)  

        {  

            int n1 = Integer.parseInt(t1.getText());  

int n2 = Integer.parseInt(t2.getText());  

t3.setText(" " + (n1 + n2));  

        }  

    }  

HTML CODE:

<HTML>  

  

    <HEAD>  

<TITLE>WELCOME TO JAVA APPLET</TITLE>  

    </HEAD>  

    <BODY>  

<CENTER>  

            <H1>WELCOME TO THE APPLET</H1> </CENTER>

<BR>

        <APPLET CODE=Q2.class WIDTH=400 HEIGHT=400> </APPLET>  

    </BODY>  

  

</HTML>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote