The final program for COP2800 is an individual program of your choosing. You dec
ID: 3698114 • Letter: T
Question
The final program for COP2800 is an individual program of your choosing. You decide what problem you want to solve and write the program to solve it. It must include a written description of what the program does and instructions about how the program works in the comments section. I do not want to see a program from the text, but all of you have interests and hobbies that you could design a program that would meet the following criteria.
Comments:
-Enough so another programmer will know what the program is doing without even reading your description.
Selection structure:
-Include either If/else logic or a case structure
Repetition structure:
-Include either While, Do While or For loop
Array:
-Any type of an array
Inheritance:
-Use Inheritance and/or Interfaces
Exception:
-Use try…catch block
Components:
-Button, TextField, Label, or ComboBox
Theme:
-There must be some point to your program, not just a collection of components
-Receives user input
-Performs output
-Add a graphic or color
To receive full credit you will design a JFrame Application that contains at least 4 of the 6, (selection, loop, array, inheritance, components or exception) plus all of the others mentioned above:-
**PLEASE HELP**
Explanation / Answer
Java program for calculator GUI: package calculator; import javax.swing.*; import java.awt.*; import java.awt.event.*; class calculator extends JFrame implements ActionListener { calculator cl=new calculator(); int s3,s1,s2; JLabel numb1,numb2,rest,rs; JPanel panel1,panel2; JButton addnum,subnum,mulnum,divnum; JTextField n1,n2,n3; calculator() { panel1=new JPanel(new FlowLayout()); panel2=new JPanel(new FlowLayout()); numb1=new JLabel("Number1"); numb2=new JLabel("Number2"); rest=new JLabel("Result"); rs=new JLabel("rgjfjj"); n1=new JTextField(10); n2=new JTextField(10); n3=new JTextField(10); addnum=new JButton("ADDITION"); subnum=new JButton("SUBTRACTION"); mulnum=new JButton("MULTIPLICATION"); divnum=new JButton("DIVISION"); addnum.addActionListener(this); mulnum.addActionListener(this); subnum.addActionListener(this); divnum.addActionListener(this); Component add1= panel1.add(numb1); Component add2= panel1.add(n1); Component add3= panel1.add(numb2); Component add4= panel1.add(n2); Component add5= panel1.add(rest); Component add6 = panel1. add(n3); Component add7 = panel2. add(addnum); Component add8 = panel2. add(subnum); Component add9 = panel2. add(mulnum); Component add10 = panel2. add(divnum); add(panel1,BorderLayout.NORTH); add(panel2,BorderLayout.SOUTH); } public void actionPerformed(ActionEvent e) { int p1=Integer.parseInt(n1.getText()); int p2=Integer.parseInt(n2.getText()); if(e.getSource()==add) // addition { p3=p1+p2; System.out.println(p3); n3.setText(Integer.toString(p3)); } else if(e.getSource()==sub) // subtraction { p3=p1-p2; System.out.println(p3); n3.setText(Integer.toString(p3)); } else if(e.getSource()==div) // division { p3=p1/p2; System.out.println(p3); n3.setText(Integer.toString(p3)); } else if(e.getSource()==mul) // multiplication { p3=p1*p2; System.out.println(p3); n3.setText(Integer.toString(p3)); } } } public class Calculatortest { public static void main(String[] args) { calculator zl=new calculator(); zl.setBounds(200, 150, 120, 550); zl.setTitle("calculator operations"); zl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); zl.setResizable(true); zl.setVisible(true); zl.setSize(500,200); }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.