Create a class that can be used to test data structure - similar to the StudentA
ID: 3662116 • Letter: C
Question
Create a class that can be used to test data structure - similar to the StudentA.java example found shown below:
The following are requirements for this homework: · Unique index integer fields · Use at least 5 other fields of various, including at least one of each of String, int and double types. o assume that the String's have no spaces within them · Write a method that will create an array of N random instances of this class, where N is an integer parameter to this method · Provide a toString method that will format an instance of this class nicely · Provide appropriate constructors · Write methods that will write and read text files of this class o to make this easy, assume that the first line of the file is the number of elements in the file o make the file one line per entry o use spaces as field delimiters in the files o use the toString method of the class to write to the file · Provide a good GUI interface to control and test this class, at a minimum: o use buttons to control the functions available o use JFileChoose for selecting input and output files o use a JTextArea and JScrollPane to create a scrolling text area for output o the window should resize nicely - use BorderLayout with the text area in the center
StudentA.java import java.util.Scanner; import java.util.ArrayList; lass StudentA lements ComparableExplanation / Answer
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/* <applet code="Stupanel" width=400 height=400>
</applet> */
public class Stupanel extends Applet implements ActionListener,ItemListener
{
String s1,s2,s3;
TextField t3,t4,t5,t6,t7;
Button tot,avg;
Checkbox c1,c2,c3,c4,m,f;
CheckboxGroup cbg;
Panel p1,p2,p3,p4;
public void init()
{
s3=" ";
tot=new Button("Total");
avg=new Button("Average");
c1=new Checkbox("MCA",true);
c2=new Checkbox("Msc Comp");
c3=new Checkbox("MSIT");
c4=new Checkbox("MSIS");
cbg=new CheckboxGroup();
m=new Checkbox("Male",cbg,false);
f=new Checkbox("Female",cbg,true);
p1=new Panel();
p1.setLayout(new GridLayout(2,2));
p1.add(new Label("Student Number "));
p1.add(new TextField(5));
p1.add(new Label("Student Name "));
p1.add(new TextField(15));
add(p1);
p2=new Panel(); p2.setLayout(new GridLayout(1,3));
p2.add(new Label("Gender"));
p2.add(m);
p2.add(f);
add(p2);
p3=new Panel(); p3.setLayout(new GridLayout(1,5));
p3.add(new Label("Degree"));
p3.add(c1); p3.add(c2); p3.add(c3); p3.add(c4);
add(p3);
p4=new Panel(); p4.setLayout(new GridLayout(6,2));
p4.add(new Label("Marks in JAVA"));
t3=new TextField(3); p4.add(t3);
p4.add(new Label("Marks in VB .Net"));
t4=new TextField(3); p4.add(t4);
p4.add(new Label("Marks In C"));
t5=new TextField(3); p4.add(t5);
p4.add(new Label("Total "));
t6=new TextField(3); p4.add(t6);
p4.add(new Label(" Average"));
t7=new TextField(3); p4.add(t7);
p4.add(tot); p4.add(avg);
tot.addActionListener(this);
avg.addActionListener(this);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
m.addItemListener(this);
f.addItemListener(this);
add(p4);
}
public void paint(Graphics g)
{
int no,m1,m2,m3,tot;
float avg=0.0f;
no=m1=m2=m3=tot=0;
try
{
m1=Integer.parseInt(t3.getText());
m2=Integer.parseInt(t4.getText());
m3=Integer.parseInt(t5.getText());
}
catch(Exception e)
{
}
tot=m1+m2+m3;
avg= tot/3;
s1=String.valueOf(tot);
s2=String.valueOf(avg);
}
public boolean action(Event e,Object o)
{
repaint();
return true;
}
public void actionPerformed(ActionEvent e)
{
s3=e.getActionCommand();
if(s3.equals("Total"))
t6.setText(s1);
if(s3.equals("Average"))
t7.setText(s2);
repaint();
}
public void itemStateChanged(ItemEvent e)
{
repaint();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.