0% found this document useful (0 votes)
18 views10 pages

Ajpmicro

Uploaded by

dhargaweamardip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views10 pages

Ajpmicro

Uploaded by

dhargaweamardip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

GOVERNMENT POLYTECHNIC

SAKOLI

A Micro project Report On

Percetnage Calculator from Marks of


Physics , Maths, Bio and English

Subject :- Advance Java Programing


(22517)
Semester: - Fifth / Third Year

Session: - 2024-2025
Submitted by

Roll Enrollment
Sr.no Name No No
Suhani D.
1. Aswale 05 2200910002
ACKNOWLEDGEMENT

This completed micro project work come as a gift to me after all the effort let
us gone in to it has been a beautiful endeavor only because of the valuable
guidance of over guide and well – wisher.

We wish to extend over the art full gratitude to over guide,

Prof. A.A. BAJPAYEE for his constant guidance encouragement motivation


for every stage of this work made this micro project a success.

Formally we are proud to express our gratitude and respect to each member.
INDEX

SR. TOPIC PAGE


NO. NO.
1. Introduction 2
2. Source Code 3-6
3. Output 7
4. References 8

1 |P a g e
INTRODUCTION

The Percentage Calculator application is a Java Swing-based tool designed to


help users calculate their overall percentage from scores in Physics, Math, Biology, and
English. This project provides a straightforward approach to mastering Java GUI
programming and basic arithmetic operations, making it ideal for beginners.

Project Overview

The Percentage Calculator application built with Java Swing, helps users
calculate their overall percentage based on marks in Physics, Math, Biology, and
English. It provides a straightforward UI for input and computes results instantly.

Key Features
1. Simple Interface: User-friendly UI for entering marks and calculating the
overall percentage.

2. Real-Time Calculation: Automatically calculates and displays the


percentage based on user input.

3. Error Handling: Validates input to ensure only valid scores are entered.

Technology Used

• Java Swing: For designing the user interface.


• Java Event Handling: To respond to button clicks for calculating
percentages.
• Input Validation: To manage correct data entry, ensuring accurate results.

2 |P a g e
SOURCE CODE

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class FixedMaxMarksPercentageCalculator {


private JTextField physicsField;
private JTextField mathsField;
private JTextField bioField;
private JTextField englishField;
private JLabel resultLabel;
private JLabel totalLabel;

public FixedMaxMarksPercentageCalculator() {
initializeUI();
}

private void initializeUI() {


// Set up the main panel
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(10, 10, 10, 10);

// Heading label
JLabel headingLabel = new JLabel("Percentage Calculator");
headingLabel.setFont(new Font("Arial", Font.BOLD, 20));
headingLabel.setForeground(new Color(0, 102, 204));
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.CENTER;
panel.add(headingLabel, gbc);

gbc.anchor = GridBagConstraints.WEST;
gbc.gridwidth = 1;
3 |P a g e
// Subject labels and text fields
physicsField = new JTextField(10);
mathsField = new JTextField(10);
bioField = new JTextField(10);
englishField = new JTextField(10);

// Result labels
resultLabel = new JLabel("Percentage: --%");
resultLabel.setFont(new Font("Arial", Font.BOLD, 16));
resultLabel.setForeground(new Color(0, 102, 102));

totalLabel = new JLabel("Total Marks: -- / 400");


totalLabel.setFont(new Font("Arial", Font.BOLD, 16));
totalLabel.setForeground(new Color(0, 102, 102));

// Add fields and labels to the panel


addField(panel, gbc, 1, "Physics (out of 100):", physicsField);
addField(panel, gbc, 2, "Maths (out of 100):", mathsField);
addField(panel, gbc, 3, "Biology (out of 100):", bioField);
addField(panel, gbc, 4, "English (out of 100):", englishField);

// Calculate button
JButton calculateButton = new JButton("Calculate");
calculateButton.setBackground(new Color(0, 153, 153));
calculateButton.setForeground(Color.WHITE);
calculateButton.setFont(new Font("Arial", Font.BOLD, 13));
calculateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
calculateResults();
}
});

// Place button and result labels on the panel


gbc.gridx = 0;
gbc.gridy = 5;
gbc.gridwidth = 2;
panel.add(calculateButton, gbc);

gbc.gridy = 6;
panel.add(totalLabel, gbc);
4 |P a g e
gbc.gridy = 7;
panel.add(resultLabel, gbc);

// Set up the frame


JFrame frame = new JFrame("Fixed Max Marks Percentage Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

private void addField(JPanel panel, GridBagConstraints gbc, int row, String label,
JTextField field) {
gbc.gridx = 0;
gbc.gridy = row;
panel.add(new JLabel(label), gbc);

gbc.gridx = 1;
panel.add(field, gbc);
}

private void calculateResults() {


try {
// Parse input values
double physics = Double.parseDouble(physicsField.getText());
double maths = Double.parseDouble(mathsField.getText());
double bio = Double.parseDouble(bioField.getText());
double english = Double.parseDouble(englishField.getText());

// Maximum total marks


double maxMarks = 400.0;

// Calculate total marks and percentage


double totalMarksObtained = physics + maths + bio + english;
double percentage = (totalMarksObtained / maxMarks) * 100;

// Display results
totalLabel.setText(String.format("Total Marks: %.2f / 400", totalMarksObtained));
resultLabel.setText(String.format("Percentage: %.2f%%", percentage));
} catch (NumberFormatException e) {
5 |P a g e
JOptionPane.showMessageDialog(null, "Please enter valid numbers for all
subjects.");
}
}

public static void main(String[] args) {


SwingUtilities.invokeLater(() -> new FixedMaxMarksPercentageCalculator());
}
}

6 |P a g e
OUTPUT

7 |P a g e
REFERENCES

• https://www.ilovepdf.com/pdf_to_word
• https://gemini.google.com/app/e25ca4620ab28eaa
• www.youtube.com
• https://www.javatpoint.com/java-swing
• https://chatgpt.com/c/6707eb4f-3fa0-8001-8fbc-
a128156a99f2
• https://www.w3schools.com

8 |P a g e

You might also like