Professional Documents
Culture Documents
Laboratory Activity Machine Problem #1:: NCP 3106 (Software Design Laboratory)
Laboratory Activity Machine Problem #1:: NCP 3106 (Software Design Laboratory)
LABORATORY ACTIVITY
CODE:
import javax.swing.*;
import java.awt.event.*; // Needed for event listener interface
import java.awt.*;
setLayout(new BorderLayout() );
1|Page
NCP 3106 (Software Design Laboratory)
button1.addActionListener(new ButtonListener());
leftPanel.add(oil);
leftPanel.add(lube);
leftPanel.add(radiator);
leftPanel.add(transmission);
leftPanel.add(inspection);
leftPanel.add(muffler);
leftPanel.add(tire);
leftPanel.add(non);
leftPanel.add(hoursTextField);
panel.add(button1);
2|Page
NCP 3106 (Software Design Laboratory)
}
}
CODE:
import java.util.Scanner;
public class NUMBA2 {
int number_Of_DaysInMonth = 0;
String MonthOfName = "Unknown";
3|Page
NCP 3106 (Software Design Laboratory)
switch (month) {
case 1:
MonthOfName = "January";
number_Of_DaysInMonth = 31;
break;
case 2:
MonthOfName = "February";
if ((year % 500 == 0) || ((year % 5 == 0) && (year % 7 != 0)))
{
number_Of_DaysInMonth = 29;
} else {
number_Of_DaysInMonth = 28;
}
break;
case 3:
MonthOfName = "March";
number_Of_DaysInMonth = 31;
break;
case 4:
MonthOfName = "April";
number_Of_DaysInMonth = 30;
break;
case 5:
MonthOfName = "May";
number_Of_DaysInMonth = 31;
break;
case 6:
MonthOfName = "June";
number_Of_DaysInMonth = 30;
break;
case 7:
MonthOfName = "July";
number_Of_DaysInMonth = 31;
break;
case 8:
MonthOfName = "August";
number_Of_DaysInMonth = 31;
break;
case 9:
MonthOfName = "September";
number_Of_DaysInMonth = 30;
break;
case 10:
MonthOfName = "October";
number_Of_DaysInMonth = 31;
break;
case 11:
MonthOfName = "November";
number_Of_DaysInMonth = 30;
4|Page
NCP 3106 (Software Design Laboratory)
break;
case 12:
MonthOfName = "December";
number_Of_DaysInMonth = 31;
}
System.out.print(MonthOfName + " " + year + " has " +
number_Of_DaysInMonth + " days\n");
}
}
CODE:
import javax.swing.*;
import java.awt.*;
5|Page
NCP 3106 (Software Design Laboratory)
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(lblHeading,BorderLayout.PAGE_START);
frame.getContentPane().add(scrollPane,BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(650, 300);
frame.setVisible(true);
}
}
FIRST FORM:
6|Page
NCP 3106 (Software Design Laboratory)
{
private final int WINDOW_WIDTH = 500;
private final int WINDOW_HEIGHT = 300;
private JPanel panel; // A holding panel
private JLabel daysLabel; // number of days on trip message
private JLabel airfareLabel; // amount of airfare message
private JLabel carRentalLabel; // amount of car rental fees
message
private JLabel milesLabel; // number of miles driven
(private vehicle)
private JLabel parkingLabel; // amount of parking fees message
private JLabel taxiLabel; // amount of taxi charges message
private JLabel registrationLabel; // registration fees message
private JLabel lodgingLabel; // lodging charges per night message
private JTextField daysField;
private JTextField airfareField;
private JTextField carRentalField;
private JTextField milesField;
private JTextField parkingField;
private JTextField taxiField;
private JTextField registrationField;
private JTextField lodgingField;
private JCheckBox airfareCheckBox;
private JCheckBox carCheckBox;
private JCheckBox privateVehicleCheckBox;
private JCheckBox taxiCheckBox;
private JButton calcButton;
/**
Cosnstructor
*/
public NUMBA4()
{
// Set the title bar text.
setTitle("Travel Expenses");
/**
The buildPanel method adds a label and text field.
*/
7|Page
NCP 3106 (Software Design Laboratory)
// Create a airfareLabel.
airfareLabel = new JLabel("Amount of airfare");
// Create a carRentalLabel.
carRentalLabel = new JLabel("Amount of car rental fees");
// Create a milesLabel.
milesLabel = new JLabel("Number of miles driven(private vehicle)");
// Create a parkingLabel.
parkingLabel = new JLabel("Amount of parking fees");
// Create a taxiLabel.
taxiLabel = new JLabel("Amount of taxi charges");
// Create a registrationLabel.
registrationLabel = new JLabel("Conference or seminar registration
fees");
// Create a lodgingLabel.
lodgingLabel = new JLabel("Lodging charges per night");
8|Page
NCP 3106 (Software Design Laboratory)
/**
CalcButtonListener is an action listener class for
the Calculate button.
*/
input = airfareField.getText();
airfare = Double.parseDouble(input);
9|Page
NCP 3106 (Software Design Laboratory)
input = carRentalField.getText();
carRental = Double.parseDouble(input);
input = milesField.getText();
miles = Double.parseDouble(input);
input = parkingField.getText();
parking = Double.parseDouble(input);
input = taxiField.getText();
taxi = Double.parseDouble(input);
input = registrationField.getText();
registration = Double.parseDouble(input);
input = lodgingField.getText();
lodging = Double.parseDouble(input);
System.exit(0);
}
}
}
SECOND FORM:
public class NUMBA4B
{
public static void main(String[] args)
{
NUMBA4 te = new NUMBA4 ();
}
}
10 | P a g e
NCP 3106 (Software Design Laboratory)
The application should calculate and display the following data for one night’s box office
business at a theater:
Gross revenue for adult tickets sold. This is the amount of money taken in for all
adult tickets sold.
Net revenue for adult tickets sold. This is the amount of money from adult ticket sales
left over after the payment to the movie company has been deducted.
Gross revenue for child tickets sold. This is the amount of money taken in for all
child tickets sold.
Net revenue for child tickets sold. This is the amount of money from child ticket sales
left over after the payment to the movie company has been deducted.
Total gross revenue. This is the sum of gross revenue for adult and child tickets sold.
Total net revenue. This is the sum of net revenue for adult and child tickets sold.
Assume the theater keeps 15 percent of its box office receipts.
11 | P a g e
NCP 3106 (Software Design Laboratory)
12 | P a g e