Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

NCP 3106 (Software Design Laboratory)

LABORATORY ACTIVITY

Machine Problem #1:


Romy’s Automotive performs the following routine maintenance services:
 Oil change—P3120.00
 Radiator flush—P500.00
 ATF flush—P2850.00
 Inspection—P150.00
 Brake replacement—P3340.00
 Tire rotation—P200.00
Romy also performs other nonroutine services and charges for parts and for labor (P300
per hour). Create a GUI application that displays the total for a customer’s visit to Romy’s.

CODE:
import javax.swing.*;
import java.awt.event.*; // Needed for event listener interface
import java.awt.*;

public class NUMBA1 extends JFrame


{
private JTextField hoursTextField;
private JCheckBox oil;
private JCheckBox lube;
private JCheckBox radiator;
private JCheckBox transmission;
private JCheckBox inspection;
private JCheckBox muffler;
private JCheckBox tire;
private JCheckBox non;
private final int WINDOW_WIDTH = 300; // Window width
private final int WINDOW_HEIGHT = 70; // Window height

public NUMBA1() /** Constructor */


{
// Set the title bar text.
setTitle("ROMY's Automotive");

// Specify what happens when the close button is clicked.


setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new BorderLayout() );

JPanel panel = new JPanel(); // A panel to hold components


JPanel leftPanel = new JPanel();

oil = new JCheckBox("Oil Change");

1|Page
NCP 3106 (Software Design Laboratory)

lube = new JCheckBox("Lube job");


radiator = new JCheckBox("Radiator flush");
transmission = new JCheckBox("Transmission flush");
inspection = new JCheckBox("Inspection");
muffler = new JCheckBox("Muffler replacement");
tire = new JCheckBox("Tire rotation");
non = new JCheckBox("Nonroutine services");
hoursTextField = new JTextField(3);
JButton button1 = new JButton("Total"); // Create the three
buttons.

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

add(panel, BorderLayout.SOUTH); // Add the panel to the content


pane.
add(leftPanel, BorderLayout.WEST);

pack(); // Automatically set the size of the window


setVisible(true); // Display the window
}

private class ButtonListener implements ActionListener


{
public void actionPerformed(ActionEvent e)
{// To hold the user's inp
String input;
double nonRoutineCost; // Cost of nonroutine services
double subTotal = 0; // Subtotal

if ( oil.isSelected() ) subTotal += 3120.00;


if ( lube.isSelected() ) subTotal += 500;
if ( radiator.isSelected() ) subTotal += 500;
if ( transmission.isSelected() ) subTotal += 2850.00;
if ( inspection.isSelected() ) subTotal += 150;
if ( muffler.isSelected() ) subTotal += 3340.00;
if ( tire.isSelected() ) subTotal += 200;
if ( non.isSelected() )
{
input = hoursTextField.getText();
nonRoutineCost = Double.parseDouble(input) * 20;
subTotal += nonRoutineCost;

2|Page
NCP 3106 (Software Design Laboratory)

JOptionPane.showMessageDialog(null, "Your subtotal comes to P" +


subTotal );

}
}

public static void main(String[] args)


{
new NUMBA1();
}

Machine Problem #2:


A retail company must file a monthly sales tax report listing the total sales for the month,
and the amount of state and county sales tax collected. The sales tax rate is 7 percent and the
value-added tax rate is 5 percent. Create a GUI application that allows the user to enter the total
sales for the month into a text field. From this figure, the application should calculate and display
the following:
 The amount of sales tax
 The amount of value-add tax
 The total sales tax (sales plus value-add)

CODE:
import java.util.Scanner;
public class NUMBA2 {

public static void main(String[] strings) {

Scanner input = new Scanner(System.in);

int number_Of_DaysInMonth = 0;
String MonthOfName = "Unknown";

3|Page
NCP 3106 (Software Design Laboratory)

System.out.print("Input a month number: ");


int month = input.nextInt();

System.out.print("Input a year: ");


int year = input.nextInt();

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

Machine Problem #3:


A county collects property taxes on the assessment value of property, which is 15 percent
of the property’s actual value. If an acre of land is valued at P700,000, its assessment value is
P105,000. The property tax is then P0.35 for each P100 of the assessment value. The tax for the
acre assessed at P105,000 will be P367.50. Create a GUI application that displays the assessment
value and property tax when a user enters the actual value of a property.

CODE:
import javax.swing.*;
import java.awt.*;

public class NUMBA3


{

public static void main(String[] args)


{
final JFrame frame = new JFrame("JTable Demo");

String[] columns = {"Name", "Value", "Total"};


double appraisedVal = 10000;
double assessedVal = appraisedVal*0.35;
double taxM = 42.28;
double taxF = (taxM/1000);
double tax = assessedVal*taxF;
Object[][] data =
{
{"Appraised Value", "="+appraisedVal, appraisedVal},
{"Assessed Value", "="+appraisedVal+"*0.35",
assessedVal},
{"Tax Rate (Mil)", "="+taxM, ""},
{"Tax Rate (factor)","="+taxM+"*(1/1000)",taxF},
{"Tax Owed", assessedVal+"*"+taxF,tax
}
};

5|Page
NCP 3106 (Software Design Laboratory)

JTable table = new JTable(data, columns);


JScrollPane scrollPane = new JScrollPane(table);
table.setFillsViewportHeight(true);

JLabel lblHeading = new JLabel("My Table");

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

Machine Problem #4:


Create a GUI application that calculates and displays the total travel expenses of a
business person on a trip. Here is the information that the user must provide:
 Number of days on the trip
 Amount of airfare, if any
 Amount of car rental fees, if any
 Number of miles driven, if a private vehicle was used
 Amount of parking fees, if any
 Amount of taxi charges, if any
 Conference or seminar registration fees, if any
 Lodging charges, per night
The company reimburses travel expenses according to the following policy:
 P250 per day for meals
 Parking fees, up to P100.00 per day
 Taxi charges up to P1500.00 per day
 Lodging charges up to P1500.00 per day
 If a private vehicle is used, P15.25 per mile driven
The application should calculate and display the following:
 Total expenses incurred by the business person
 The total allowable expenses for the trip
 The excess that must be paid by the business person, if any
 The amount saved by the business person if the expenses are under the total
allowed

FIRST FORM:

import javax.swing.*; // Needed for Swing classes


import java.awt.event.*;
import java.text.DecimalFormat;
import java.awt.*;
public class NUMBA4 extends JFrame

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

// Set the size of the window.


setSize(WINDOW_WIDTH, WINDOW_HEIGHT);

// Specify an action for the close button.


setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Build the panel and add it to the frame.


buildPanel();

// Add the panel to the frame's content pane.


add(panel);

// Display the window.


setVisible(true);
}

/**
The buildPanel method adds a label and text field.
*/

7|Page
NCP 3106 (Software Design Laboratory)

private void buildPanel()


{
// Create a daysLabel.
daysLabel = new JLabel("Number of days on the trip");

// Create a text field 5 characters wide.


daysField = new JTextField(5);

// Create a airfareLabel.
airfareLabel = new JLabel("Amount of airfare");

// Create a text field 5 characters wide.


airfareField = new JTextField(5);

// Create a carRentalLabel.
carRentalLabel = new JLabel("Amount of car rental fees");

// Create a text field 5 characters wide.


carRentalField = new JTextField(5);

// Create a milesLabel.
milesLabel = new JLabel("Number of miles driven(private vehicle)");

// Create a text field 5 characters wide.


milesField = new JTextField(5);

// Create a parkingLabel.
parkingLabel = new JLabel("Amount of parking fees");

// Create a text field 5 characters wide.


parkingField = new JTextField(5);

// Create a taxiLabel.
taxiLabel = new JLabel("Amount of taxi charges");

// Create a text field 5 characters wide.


taxiField = new JTextField(5);

// Create a registrationLabel.
registrationLabel = new JLabel("Conference or seminar registration
fees");

// Create a texi field 5 characters wide.


registrationField = new JTextField(5);

// Create a lodgingLabel.
lodgingLabel = new JLabel("Lodging charges per night");

// Create a button with the caption "Calculate".


calcButton = new JButton("Calculate");

// Add an action listener to the button.


calcButton.addActionListener(new CalcButtonListener());

// Create a JPanel object and let the panel

8|Page
NCP 3106 (Software Design Laboratory)

// field reference it.


panel = new JPanel();

// Add the label, text field components to the panel.


panel.add(daysLabel);
panel.add(daysField);
panel.add(airfareLabel);
panel.add(airfareField);
panel.add(carRentalLabel);
panel.add(carRentalField);
panel.add(milesLabel);
panel.add(milesField);
panel.add(parkingLabel);
panel.add(parkingField);
panel.add(taxiLabel);
panel.add(taxiField);
panel.add(registrationLabel);
panel.add(registrationField);
panel.add(lodgingLabel);
panel.add(lodgingField);
panel.add(calcButton);
}

/**
CalcButtonListener is an action listener class for
the Calculate button.
*/

private class CalcButtonListener implements ActionListener


{
/**
The actionPerformed method executes when the user
clicks on the Calculate button.
#param e The event object.
*/

public void actionPerformed(ActionEvent e)


{
String input; // To hold the user's input
double days; // the number of days.
double airfare;
double carRental;
double miles;
double parking;
double taxi;
double registration;
double lodging;
double total;

// Get the text entered by the user into


// the text field.
input = daysField.getText();
days = Double.parseDouble(input);

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

// Calculate the total.


total = days + airfare + carRental + miles +
parking + taxi + registration + lodging;

// Create a DecimalFormat object to format output.


DecimalFormat dollar = new DecimalFormat("0.00");

// Display the charges.


JOptionPane.showMessageDialog(null, "Total: $" + total);

System.exit(0);
}
}
}

SECOND FORM:
public class NUMBA4B
{
public static void main(String[] args)
{
NUMBA4 te = new NUMBA4 ();
}
}

Machine Problem #5:


A movie theater only keeps a percentage of the revenue earned from ticket sales. The remainder
goes to the movie company. Create a GUI application that allows the user to enter the following
data into text fields:
 Price per adult ticket
 Number of adult tickets sold
 Price per child ticket
 Number of child tickets sold

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

You might also like