I am placing the my code for the assignment below. I have everything working but
ID: 3657377 • Letter: I
Question
I am placing the my code for the assignment below. I have everything working but I do not have the class design correct. THe assignment calls for two classes one that does only the calculation and the other that does everything else. If you look at my code you will see that is not what I have. I need help changing it to fit the class assignment correctly. First Class - KristiConverter.java import javax.swing.*; public class KristiConverter { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //Created the main frame and the methods for the buttons JFrame frame = new KristiConverterFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("KristiConverter"); frame.setVisible(true); frame.setSize(425, 250); } } Second Class - KristiCoverterFrame.java import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import java.text.DecimalFormat; @SuppressWarnings("serial") public class KristiConverterFrame extends JFrame { // Defines the buttons, Frame, Panel, TestFields, and Labels to be used private ActionListener btnhear; private JRadioButton InCelcuisRB, InFahrenRB, InKelvinRB, OutCelcuisRB, OutFahrenRB, OutKelvinRB; private JTextField InputFld = new JTextField(10); private JTextField OutputFld = new JTextField(10); private JLabel InputLbl = new JLabel("Temperature to be Converted"); private JLabel OutputLbl = new JLabel("Converted Temperature"); //Sets up the formatting for the decimal places DecimalFormat Threeplaces = new DecimalFormat("0.000"); public KristiConverterFrame() { JPanel gcINPanel = new JPanel(); //gcPanel.setLayout(new FlowLayout()); gcINPanel.add(InputLbl); gcINPanel.add(InputFld); add(gcINPanel, BorderLayout.NORTH); //setVisible(true); //setTitle("Garrett's Temp Converter"); //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel gcOUTPanel = new JPanel(); gcOUTPanel.add(OutputLbl); gcOUTPanel.add(OutputFld); OutputFld.setEditable(false); add(gcOUTPanel, BorderLayout.SOUTH); class ItemListener implements ActionListener { public void actionPerformed(ActionEvent event) { conversionPerformed();//performed when a button is selected } } btnhear = new ItemListener(); //The following sections create the radio buttons //public JPanel createRadioButtons() { InCelcuisRB = new JRadioButton("Celcuis"); InCelcuisRB.addActionListener(btnhear); InFahrenRB = new JRadioButton("Fahrenheit"); InFahrenRB.addActionListener(btnhear); InKelvinRB = new JRadioButton("Kelvin"); InKelvinRB.addActionListener(btnhear); OutCelcuisRB = new JRadioButton("Celcuis"); OutCelcuisRB.addActionListener(btnhear); OutFahrenRB = new JRadioButton("Fahrenheit"); OutFahrenRB.addActionListener(btnhear); OutKelvinRB = new JRadioButton("Kelvin"); OutKelvinRB.addActionListener(btnhear); ButtonGroup westGroup = new ButtonGroup(); westGroup.add(InCelcuisRB); westGroup.add(InFahrenRB); westGroup.add(InKelvinRB); JPanel gcINPUT = new JPanel(); gcINPUT.add(new JLabel("Input Scale")); gcINPUT.setLayout(new GridLayout(4, 1)); gcINPUT.add(InCelcuisRB); gcINPUT.add(InFahrenRB); gcINPUT.add(InKelvinRB); add(gcINPUT, BorderLayout.WEST); ButtonGroup eastGroup = new ButtonGroup(); eastGroup.add(OutCelcuisRB); eastGroup.add(OutFahrenRB); eastGroup.add(OutKelvinRB); JPanel gcOUTPUT = new JPanel(); gcOUTPUT.setLayout(new GridLayout(4, 1)); gcOUTPUT.add(new JLabel("Output Scale")); gcOUTPUT.add(OutCelcuisRB); gcOUTPUT.add(OutFahrenRB); gcOUTPUT.add(OutKelvinRB); add(gcOUTPUT, BorderLayout.EAST); //} } public void conversionPerformed() { //This is the place where the values are retrieved and the conversions take place int temp; double converttemp = 0.00; String inputString = InputFld.getText(); temp = Integer.parseInt(inputString); if (InFahrenRB.isSelected() & OutCelcuisRB.isSelected()) converttemp = (5.0/9.0) * temp - 32; //Fahrenheit to Celcuis else if (InFahrenRB.isSelected() & OutKelvinRB.isSelected()) converttemp = ((.55555) * (temp - 32) + 273); else if (InCelcuisRB.isSelected() & OutFahrenRB.isSelected()) converttemp = (((1.8) * temp) + 32); else if (InCelcuisRB.isSelected() & OutKelvinRB.isSelected()) converttemp = (temp + 273); else if (InKelvinRB.isSelected() & OutFahrenRB.isSelected()) converttemp = (((temp - 273) * 1.8) + 32); else if (InKelvinRB.isSelected() & OutCelcuisRB.isSelected()) converttemp = (temp - 273); else if (InFahrenRB.isSelected() & OutFahrenRB.isSelected()) converttemp = temp; else if (InKelvinRB.isSelected() & OutKelvinRB.isSelected()) converttemp = temp; else if (InCelcuisRB.isSelected() & OutCelcuisRB.isSelected()) converttemp = temp; OutputFld.setText(" " + Threeplaces.format(converttemp)); } }Explanation / Answer
You can count on me like 1..2..3..and I'll be there..cuz thats wat friends are supposed to do.. lol..jst testing my keyboard! ;) Heya..I guess cramster messed up wid ur free spacings in b/w..So its a li'l difficult to understand it in first place..much less formatting it into two diff codes..Hope some other takes the patience and helps ya! btw..Y dont yu ask your friends to help yu out..Bruno Mars says U can count on them! :)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.