Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
61 views

Java Assisgnment Solution: Q6

This document contains code snippets from Java assignments that demonstrate different programming concepts: 1. Calculating student grades based on percentage and medical/non-medical sections. 2. Creating a Report class to calculate average marks and display pass/fail status. 3. Adding and removing items from list and combo boxes. 4. Calculating net price after applying discounts on listed product prices. 5. Calculating interest on principal amount for fixed/recurring deposits applying different interest rates. 6. Creating a Batsman class to calculate batting average from innings, not outs and runs scored.

Uploaded by

Aditya Upadhyay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Java Assisgnment Solution: Q6

This document contains code snippets from Java assignments that demonstrate different programming concepts: 1. Calculating student grades based on percentage and medical/non-medical sections. 2. Creating a Report class to calculate average marks and display pass/fail status. 3. Adding and removing items from list and combo boxes. 4. Calculating net price after applying discounts on listed product prices. 5. Calculating interest on principal amount for fixed/recurring deposits applying different interest rates. 6. Creating a Batsman class to calculate batting average from innings, not outs and runs scored.

Uploaded by

Aditya Upadhyay
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Java Assisgnment Solution:

Q6.

private void cmdCalcGradeActionPerformed(java.awt.event.ActionEvent evt) {


float per = Float.valueOf(txtPer.getText());
String gr="";
// Medical section
if (optMed.isSelected()) {
if (per >= 80)
gr = "A";
else
if (per >= 60 && per <= 78)
gr = "B";
else
if (per < 60)
gr = "C";
}
// Non-Medical section
else
if (optNMed.isSelected()) {
if (per >= 75)
gr = "A";
else
if (per >= 50 && per <= 74)
gr = "B";
else
if (per < 50)
gr = "C";
}
txtGr.setText(gr);
}

private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {


txtFirst.setText("");
txtSecond.setText("");
txtPer.setText("");
txtGr.setText("");
chkNCC.setSelected(false);
optMed.setSelected(true); // Default button selected
optNMed.setSelected(false);
}

private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {


System.exit(0);
}

private void btnDisActionPerformed(java.awt.event.ActionEvent evt) {


txtPer.enable(false);
txtGr.enable(false);
optMed.setSelected(true); // Default button selected
optNMed.setSelected(false);
}

private void cmdCalcPerActionPerformed(java.awt.event.ActionEvent evt) {


int fTerm, sTerm;
int Total=0;
float per=0;
fTerm = Integer.parseInt(txtFirst.getText());
sTerm = Integer.parseInt(txtSecond.getText());
Total = fTerm + sTerm; // Total marks
per = Total/2; // Percentage of marks
if (chkNCC.isSelected())
per = per + 3; // Extra 3% is given as NCC Cadet
// Displaying percentage
txtPer.setText(Float.toString(per));
}
------------------------------------------------------------------------------------------------------------------------
Q7. class Report
{
int adno;
String Name;
float M1, M2, M3, M4, M5;
float average;
float getavg( )
{
return ((M1 + M2 + M3 + M4 + M5)/5);
}
void read_info( )
{
adno = Integer.parseInt(txtAdm.getText());
Name = txtSname.getText();
M1 = Integer.parseInt(txtM1.getText());
M2 = Integer.parseInt(txtM2.getText());
M3 = Integer.parseInt(txtM3.getText());
M4 = Integer.parseInt(txtM4.getText());
M5 = Integer.parseInt(txtM5.getText());
average = getavg();
}
void displayinfo()
{
txtAvg.setText(Float.toString(average));
if (average > 40) {
jLabel5.setText("You are passed");
jLabel5.setForeground(Color.blue);
}
else {
jLabel5.setText("You are failed");
jLabel5.setForeground(Color.red);
}
}
}
private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

private void btnAvgActionPerformed(java.awt.event.ActionEvent evt) {


// Report class object
Report RP = new Report();
// Member method accessed through class object
RP.read_info();
RP.displayinfo();
}
----------------------------------------------

Q8.
private void cmdListActionPerformed(java.awt.event.ActionEvent evt) {

String City = txtCity.getText();


DefaultListModel dModel = (DefaultListModel)
jList1.getModel();
dModel.addElement(City);
jList1.setModel(dModel);
}

private void cmdLCActionPerformed(java.awt.event.ActionEvent evt) {


DefaultListModel dModel = (DefaultListModel) jList1.getModel();
dModel.clear();
}

private void cmdComboActionPerformed(java.awt.event.ActionEvent evt) {


String City = txtCity.getText();
DefaultComboBoxModel cModel = (DefaultComboBoxModel) jComboBox1.getModel();
cModel.addElement(City);
jComboBox1.setModel(cModel);
}

private void cmdCCActionPerformed(java.awt.event.ActionEvent evt) {


DefaultComboBoxModel cModel = (DefaultComboBoxModel) jComboBox1.getModel();
cModel.removeAllElements();
}

private void cmdLCIndActionPerformed(java.awt.event.ActionEvent evt) {


String City = (String) jList1.getSelectedValue();
int ind = jList1.getSelectedIndex();
if (jList1.isSelectedIndex(ind)) {
DefaultListModel dModel = (DefaultListModel) jList1.getModel();
dModel.remove(ind);
JOptionPane.showMessageDialog(this, "Deleted name " + City);
jList1.setModel(dModel);
} else
JOptionPane.showMessageDialog(this, "No name is selected from list");
}
private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
txtCity.setText("");
}

private void cmdCBIndActionPerformed(java.awt.event.ActionEvent evt) {


String City = (String) jComboBox1.getSelectedItem();
int ind = jComboBox1.getSelectedIndex();
DefaultComboBoxModel cModel = (DefaultComboBoxModel) jComboBox1.getModel();
cModel.removeElementAt(ind);
JOptionPane.showMessageDialog(this, "Deleted name " + City);
jComboBox1.setModel(cModel);
}

Q9.
private void cmdNetActionPerformed(java.awt.event.ActionEvent evt) {
float NetPrice;
NetPrice = Float.parseFloat(txtLPrice.getText()) - Float.parseFloat(txtDiscount.getText());
txtNPrice.setText(Float.toString(NetPrice));
}

private void cmdListActionPerformed(java.awt.event.ActionEvent evt) {


String Product = cmbProduct.getSelectedItem().toString();
if (Product.equals("Washing Machine")) {
txtLPrice.setText("12000");
} else if (Product.equals("Color Television")) {
txtLPrice.setText("17000");
} else if (Product.equals("Refrigerator")) {
txtLPrice.setText("18000");
} else if (Product.equals("OTG")) {
txtLPrice.setText("8000");
} else if (Product.equals("CD Player")) {
txtLPrice.setText("14500");
}
}

private void cmdDiscActionPerformed(java.awt.event.ActionEvent evt) {


// TODO add your handling code here:
float ProductPrice, Discount;
ProductPrice = Float.parseFloat(txtLPrice.getText());
// Calculating Discount Price
if (optFest.isSelected()) {
Discount = ProductPrice * 17 /100;
} else {
Discount = ProductPrice * 10 /100;
}
txtDiscount.setText(Float.toString(Discount));
}
private void cndExutActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
------------------------------------------------------------------------------------

Q10.
private void cmdExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

private void cmdCalculateActionPerformed(java.awt.event.ActionEvent evt) {


int T = Integer.parseInt(txtTime.getText());
double CI = 0, Amount =0;
double P = Double.parseDouble(txtPrincipal.getText());
float R = 0;
if (optFD.isSelected())
{
if (T<=1)
R = 10;
else
if ((T>1) && (T<=5))
R = 12;
else
if (T>5)
R = 15;
}
else
if (optRD.isSelected())
{
if (T<=2)
R = 10;
else
if ((T>2) && (T<=7))
R = 12;
else
if (T>7)
R = 15;
}
if (chkSR.isSelected())
R = R + 2;
txtRate.setText(Float.toString(R));
CI = P * Math.pow((1 + (R/100)), T);
Amount = P + CI;
txtInterest.setText(String.valueOf(CI));
txtAmount.setText(String.valueOf(Amount));

}
private void cmdClearActionPerformed(java.awt.event.ActionEvent evt) {
txtPrincipal.setText("");
txtTime.setText("");
txtRate.setText("");
txtInterest.setText("");
txtAmount.setText("");
optFD.setSelected(true); // Default button selected
optRD.setSelected(false); // Default button selected
}
------------------------------------------------------------------------------------------------------------

Q11.
class Batsman
{
int bcode;
String bname;
int innings, notout, runs;
float batavg;
float calcavg()
{
return (runs/(innings-notout));
}
void readdata()
{
bcode = Integer.parseInt(txtCode.getText());
bname = txtName.getText();
innings = Integer.parseInt(txtIn.getText());
notout = Integer.parseInt(txtNot.getText());
runs = Integer.parseInt(txtRuns.getText());
batavg = calcavg();
}
void displaydata()
{
txtAvg.setText(Float.toString(batavg));
}
}
private void btnAvgActionPerformed(java.awt.event.ActionEvent evt) {
Batsman BT = new Batsman();
BT.readdata();
BT.displaydata();
}

private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {


System.exit(0);
}
--------------------------------------------------------------------------------------------------

Q14.
private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

private void btnIncActionPerformed(java.awt.event.ActionEvent evt) {


int sales = 0;

if (!txtSales.getText().trim().equals("")) {
sales =
Integer.parseInt(txtSales.getText().trim());
}

double incentive = 0.0;

if (jCheckBox1.isSelected()) {
incentive = incentive + 0.1; // 10%
}
if (jCheckBox2.isSelected()) {
incentive = incentive + 0.08; // 8%
}
if (jCheckBox3.isSelected()) {
incentive = incentive + 0.05; // 5%
}
txtInc.setText("" + Math.round(sales * incentive));
}
----------------------------------------------------------------------------------------------------------------

Q15.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

private void btnStringActionPerformed(java.awt.event.ActionEvent evt) {


String Name = txtName.getText();
String School = txtSch.getText();
String nName = Name.concat(School);
int nlength = Name.length();
String nStr = Name.substring(9);
String nStr1 = School.substring(9, 13);
String uCase = Name.toUpperCase();
String LCase = School.toLowerCase();
String mess1 = " My Personal Bio-Data ";
String Year = "2014";
String nTrim = mess1.trim() + " " + Year;
txtStringArea.append("Concatenated string: " + nName + "\n");
txtStringArea.append("Length of '" + Name + "' is: " + nlength + "\n");
txtStringArea.append("Name.substring(9) is: " + nStr + "\n");
txtStringArea.append("School.substring(9, 13) is: " + nStr1 + "\n");
txtStringArea.append("Name.toUpperCase() is: " + uCase + "\n");
txtStringArea.append("School.toLowerCase() is: " + LCase + "\n");
txtStringArea.append("mess1 trim is: " + nTrim + "\n");
}

You might also like