Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Writing a program to calculate the terms of the following sequence

Writing a program to calculate the terms of the following sequence

of numbers: 0 1 3 8 21 55 144 377 … where each term is three times the previous term minus the second previous term.

1. Class P3GUI should define the Swing based GUI and should be hand-coded and not generated by a GUI generator. In addition to the main method and a constructor to build the GUI, an event handler will be needed to handle the Compute button click and another handler will be needed to produce the file described above when the window is closed. The latter handler should be an object of an inner class that extends the WindowAdapter class.

2. Class Sequence should be a utility class meaning that all its methods must be class (static) methods and no objects should be able to be generated for that class. It should contain three public methods:

/*** Created by bigh2 on 9/28/2017.*/import javax.sound.midi.Sequence;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;public class P3GUI extends JFrame implements ActionListener{private final String fileName = “output.txt”;private PrintWriter pOutput;private FileWriter fWriter;private BufferedWriter buffWriter;// Font settings and creates a new JFrameprivate final Font guiFont = new Font (“Times New Roman”, Font.BOLD, 16);private final JFrame guiFrame = new JFrame();// Radiobutton for Iterative or Recursiveprivate final JRadioButton iBtn = new JRadioButton(“Iterative”);private final JRadioButton rBtn = new JRadioButton(“Recursive”);// Buttons for User Inputprivate final ButtonGroup userInput = new ButtonGroup();private final JLabel inputLabel = new JLabel(“Input a number: “);private final JLabel outputLabel = new JLabel(“Output: “);private final JLabel eLabel = new JLabel(“Efficiency: “);// Textfield for input and outputprivate final JTextField inputField = new JTextField(20);private final JTextField outputField = new JTextField();private final JTextField eField = new JTextField();// Button to calculateprivate final JButton calculateBtn = new JButton(“Calculate”);// Panels for input, buttons, choice, answer and mainprivate final JPanel panelMain = new JPanel();private final JPanel buttonPanel = new JPanel();private final JPanel choicePanel = new JPanel();private final JPanel panelInput = new JPanel();private final JPanel panelOutput = new JPanel();// Constructorpublic P3GUI() {setFrame();setAttributes();setPanels();addWindowListener(new AppClose());}// Method to set the settings of the Frameprivate void setFrame() {setVisible(true);setSize(600, 300);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setTitle(“Project 3: Iterative vs. Recursive”);add(panelMain);
Background image of page 1
}// Method to set Attributesprivate void setAttributes() {// Using GridLayout to set format of panelspanelMain.setLayout(new GridLayout(4,1));panelOutput.setLayout(new GridLayout(2,2));// Adding buttons to the user selection paneluserInput.add(iBtn);userInput.add(rBtn);// Setting fontsiBtn.setFont(guiFont);rBtn.setFont(guiFont);inputLabel.setFont(guiFont);outputLabel.setFont(guiFont);eLabel.setFont(guiFont);calculateBtn.setFont(guiFont);// Defaults on the fields and buttons.outputField.setEditable(false);eField.setEditable(false);iBtn.setSelected(true);calculateBtn.addActionListener(new guiClickButton());}public void setPanels() {// Add iterative and recursive buttons to choicePanelchoicePanel.add(iBtn);choicePanel.add(rBtn);// Add user inputs to Input PanelpanelInput.add(inputLabel);panelInput.add(inputField);// Add Calculate to button panelbuttonPanel.add(calculateBtn);// Add efficiency and output to Output PanelpanelOutput.add(outputLabel);panelOutput.add(outputField);panelOutput.add(eLabel);panelOutput.add(eField);// Adds the four above panels to the main panelpanelMain.add(choicePanel);panelMain.add(panelInput);panelMain.add(buttonPanel);panelMain.add(panelOutput);}// Calls the sequence.java class based on user input and calculatesinformation// based on if recursive of iterative is selected.private void callSequence(int a) {if(iBtn.isSelected()) {int iValue = Sequence.iterativeCalc(a);long iEff = (Sequence.counter + 1);outputField.setText(Integer.toString(iValue));eField.setText(Long.toString(iEff));
Background image of page 2

Show 

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"