[go: up one dir, main page]

0% found this document useful (0 votes)
49 views17 pages

IT2213 Assessment6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 17

DEL ROSARIO MICHAEL GILBERT B.

BSIT-2B
IT-2213 Object Oriented Programming 2(JAVA)
MR. AGUADO

Assessment Task. [Module 6]

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:

15. A JTextField that can display 15 characters

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{

private static final int WIDTH = 350;


private static final int HEIGHT = 400;
private JLabel testScore1, testScore2, testScore3,
testScore4,calculateScore;
private JLabel weight1, weight2, weight3,
weight4,calculateWeight;
private JTextField testScore1TF, testScore2TF,
testScore3TF, testScore4TF,answerTF;
private JTextField weight1TF, weight2TF, weight3TF,
weight4TF,answer;
private JButton calculate;
//HANDLER
private CalculateButtonHandler aveButton;
//CONSTRUCTOR
public Assessments() {
setTitle("Average of four test score");
//CONTAINER
Container pane;
pane = getContentPane();
pane.setLayout(new GridLayout(9,2));
pane.setBackground(Color.PINK);
//INSTANTIATION
testScore1 = new JLabel("Test Score 1 :
",SwingConstants.RIGHT);
testScore2 = new JLabel("Test Score 2 :
",SwingConstants.RIGHT);
testScore3 = new JLabel("Test Score 3 :
",SwingConstants.RIGHT);
testScore4 = new JLabel("Test Score 4 :
",SwingConstants.RIGHT);

weight1 = new JLabel("Weight 1 :


",SwingConstants.RIGHT);
weight2 = new JLabel("Weight 2 :
",SwingConstants.RIGHT);
weight3 = new JLabel("Weight 3 :
",SwingConstants.RIGHT);
weight4 = new JLabel("Weight 4 :
",SwingConstants.RIGHT);

calculate = new JButton("Calculate");


aveButton = new CalculateButtonHandler();
calculate.addActionListener(aveButton);

testScore1TF = new JTextField(10);


testScore2TF = new JTextField(10);
testScore3TF = new JTextField(10);
testScore4TF = new JTextField(10);

weight1TF = new JTextField(10);


weight2TF = new JTextField(10);
weight3TF = new JTextField(10);
weight4TF = new JTextField(10);
answer = new JTextField(10);
//ADDING COMPONENTS ON PANE
pane.add(testScore1);
pane.add(testScore1TF);
pane.add(weight1);
pane.add(weight1TF);
pane.add(testScore2);
pane.add(testScore2TF);
pane.add(weight2);
pane.add(weight2TF);
pane.add(testScore3);
pane.add(testScore3TF);
pane.add(weight3);
pane.add(weight3TF);
pane.add(testScore4);
pane.add(testScore4TF);
pane.add(weight4);
pane.add(weight4TF);
pane.add(calculate);
pane.add(answer);
//CHANGING FONT STYLE
testScore1.setFont(new Font("MV Boli",
Font.PLAIN,15));
weight1.setFont(new Font("MV Boli",
Font.PLAIN,15));
testScore2.setFont(new Font("MV Boli",
Font.PLAIN,15));
weight2.setFont(new Font("MV Boli",
Font.PLAIN,15));
testScore3.setFont(new Font("MV Boli",
Font.PLAIN,15));
weight3.setFont(new Font("MV Boli",
Font.PLAIN,15));
testScore4.setFont(new Font("MV Boli",
Font.PLAIN,15));
weight4.setFont(new Font("MV Boli",
Font.PLAIN,15));
calculate.setFont(new Font("MV Boli",
Font.PLAIN,15));

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);
}

public static void main(String[] args) {


Assessments obj1 = new Assessments();
}

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");

//ADDING COMPONENTS TO THE PANE


pane.add(inputSeconds);
pane.add(inputSecondsTF);
pane.add(years);
pane.add(yearTF);
pane.add(weeks);
pane.add(weeksTF);
pane.add(days);
pane.add(daysTF);
pane.add(hours);
pane.add(hoursTF);
pane.add(minutes);
pane.add(minutesTF);
pane.add(seconds);
pane.add(secondsTF);
pane.add(calculate);
pane.add(exit);

//CHANGING FONT STYLE


inputSeconds.setFont(new Font("MV Boli",
Font.PLAIN,15));
years.setFont(new Font("MV Boli", Font.PLAIN,15));
weeks.setFont(new Font("MV Boli", Font.PLAIN,15));
days.setFont(new Font("MV Boli", Font.PLAIN,15));
hours.setFont(new Font("MV Boli", Font.PLAIN,15));
minutes.setFont(new Font("MV Boli",
Font.PLAIN,15));
seconds.setFont(new Font("MV Boli",
Font.PLAIN,15));
calculate.setFont(new Font("MV Boli",
Font.PLAIN,15));
exit.setFont(new Font("MV Boli", Font.PLAIN,15));

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 + "");
}
}

public static void main(String[] args) {


convertSeconds obj1 = new convertSeconds();
}

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;

public class compareTwoStrings extends JFrame{


private JLabel firstString,secondString;
private JTextField
forFirstString,forSecondString,result;
private JButton run;
private ButtonHandler handler;

public compareTwoStrings(){ //CONSTRUCTOR


setTitle("Comparing Two String");
// CONTAINER
Container pane = getContentPane();
pane.setLayout(new GridLayout(3,1));
pane.setBackground(Color.pink);

//INSTANTIATION AND ADDING COMPONENTS ON PANE


firstString = new JLabel("Enter first string :
",SwingConstants.RIGHT);
pane.add(firstString);

forFirstString = new JTextField(10);


pane.add(forFirstString);
secondString = new JLabel("Enter second string:
",SwingConstants.RIGHT);
pane.add(secondString);

forSecondString = new JTextField(10);


pane.add(forSecondString);

run = new JButton("Compare");


pane.add(run);
//HANDLER BUTTON
handler = new ButtonHandler();
run.addActionListener(handler);

result = new JTextField(10);


pane.add(result);

firstString.setFont(new Font("MV Boli",


Font.PLAIN,15));
secondString.setFont(new Font("MV Boli",
Font.PLAIN,15));
run.setFont(new Font("MV Boli", Font.PLAIN,15));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,200);

}
//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.");
}
}

public static void main(String[] args) {


compareTwoStrings obj1 = new compareTwoStrings();
}

OUTPUT:

You might also like