IT2213 Assessment6
IT2213 Assessment6
IT2213 Assessment6
BSIT-2B
IT-2213 Object Oriented Programming 2(JAVA)
MR. AGUADO
1. True
2. True
3. False
4. True
5. False
6. False
7. True
8. True
9. True
10. False
11. False
12. True
13. A JLabel with the text string “Enter the number of courses”
Answer:
14. A JButton with the text string “Run”
Answer:
Answer:
16. A window with the title “Welcome Home”
Answer:
17. A window with a width of 200 pixels and a height of 400 pixels
Answer:
18. A JTextField that displays the string “Apple Tree”
Answer:
PROGRAMMING:
1.
package HelloWorld;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Assessments extends JFrame{
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(HIDE_ON_CLOSE);
setVisible(true);
}
//BUTTON HANDLER METHOD
private class CalculateButtonHandler implements
ActionListener{
public void actionPerformed(ActionEvent e){
double
testScores01,testScores02,testScores03,testScores04;
double weight01, weight02, weight03,
weight04, average;
testScores01 =
Double.parseDouble(testScore1TF.getText());
weight01 =
Double.parseDouble(weight1TF.getText());
testScores02 =
Double.parseDouble(testScore2TF.getText());
weight02 =
Double.parseDouble(weight2TF.getText());
testScores03 =
Double.parseDouble(testScore3TF.getText());
weight03 =
Double.parseDouble(weight3TF.getText());
testScores04 =
Double.parseDouble(testScore4TF.getText());
weight04 =
Double.parseDouble(weight4TF.getText());
average = (testScores01*weight01 +
testScores02*weight02 + testScores03*weight03 +
testScores04*weight04) / (weight01 + weight02
+ weight03 + weight04);
answer.setText(" " + average);
}
OUTPUT:
2.
package HelloWorld;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JTextField;
import java.awt.Window.Type;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class convertSeconds {
private JFrame converter;
private JLabel inputSeconds, years, weeks, days, hours,
minutes, seconds;
private JTextField inputSecondsTF, yearTF, weeksTF,
daysTF, hoursTF,
minutesTF, secondsTF;
private JButton calculate, exit;
private CalculateButtonHandler calculateButton;
protected Object frame;
//CONSTRUCTOR
public convertSeconds(){
converter = new JFrame();
converter.setTitle("Seconds Converter");
//CONTAINER
Container pane;
pane = converter.getContentPane();
pane.setLayout(new GridLayout(8,1));
pane.setBackground(Color.PINK);
//INSTANTIATION
//LABELS
inputSeconds = new JLabel("Input Seconds:
",SwingConstants.RIGHT);
years = new JLabel("Year :
",SwingConstants.RIGHT);
weeks = new JLabel("Weeks :
",SwingConstants.RIGHT);
days = new JLabel("Days :
",SwingConstants.RIGHT);
hours = new JLabel("Hours :
",SwingConstants.RIGHT);
minutes = new JLabel("Minutes :
",SwingConstants.RIGHT);
seconds = new JLabel("Seconds :
",SwingConstants.RIGHT);
//TEXTFIELDS
inputSecondsTF = new JTextField(10);
yearTF = new JTextField(10);
weeksTF = new JTextField(10);
daysTF = new JTextField(10);
hoursTF = new JTextField(10);
minutesTF = new JTextField(10);
secondsTF = new JTextField(10);
//BUTTONS
calculate = new JButton("Calculate");
calculateButton = new CalculateButtonHandler();
calculate.addActionListener(calculateButton);
exit = new JButton("Exit");
converter.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
converter.setVisible(true);
converter.setSize(300,400);
}
//BUTTON HANDLER METHOD
private class CalculateButtonHandler implements
ActionListener{
public void actionPerformed(ActionEvent e) {
int secondsInput =
Integer.parseInt(inputSecondsTF.getText());
int years = secondsInput/31536000;
int weeks = secondsInput %31536000/604800;
int days = (secondsInput % 604800) / 86400;
int hours = ((secondsInput % 604800) % 86400)
/ 3600;
int minutes = (((secondsInput % 604800) %
86400) % 3600) / 60;
int seconds = (((secondsInput % 604800) %
86400) % 3600) % 60;
yearTF.setText(years + "");
weeksTF.setText(weeks + "");
daysTF.setText(days + "");
hoursTF.setText(hours + "");
minutesTF.setText(minutes + "");
secondsTF.setText(seconds + "");
}
}
OUTPUT:
3.
package HelloWorld;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
}
//BUTTON HANDLER METHOD
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e) {
String s1 , s2;
s1 = forFirstString.getText();
s2 = forSecondString.getText();
if (s1.compareTo(s2) > 0)
result.setText(s1 + " is greater than " +
s2);
else if (s1.compareTo(s2) <0)
result.setText(s1 + " is smaller than " +
s2);
else
result.setText("Both the strings are
equal.");
}
}
OUTPUT: