Professional Documents
Culture Documents
1BM23MC110_AAT1
1BM23MC110_AAT1
COLLEGE OF ENGINEERING
2023-2025
“JAVA PROGRAMMING”
(22MCA2PCJP)
BY
Vandana B Gowda
1BM23MC110
MCA 2ND SEM
B SECTION
(Assistant Professor)
CONTENTS
package practice;
import java.util.Scanner;
scanner.close();
}
package producttax;
package producttax;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
System.out.print("Price: ");
double price = scanner.nextDouble();
double totalOriginalPrice = 0;
double totalTaxAmount = 0;
double totalPriceAfterTax = 0;
System.out.println("\nReceipt:");
System.out.println("-------------------------------------------------");
for (Product product : products) {
double taxAmount = product.calculateTax();
double totalPrice = product.getTotalPrice();
totalOriginalPrice += product.getPrice();
totalTaxAmount += taxAmount;
totalPriceAfterTax += totalPrice;
}
System.out.println("Summary:");
System.out.println("Total Original Price: $" + totalOriginalPrice);
System.out.println("Total Tax Amount: $" + totalTaxAmount);
System.out.println("Total Price after Tax: $" + totalPriceAfterTax);
scanner.close();
}
package insurancepremium;
public Person(String name, int age, boolean smokes, boolean drinks, boolean
hasPreExistingCondition, char gender) {
this.name = name;
this.age = age;
this.smokes = smokes;
this.drinks = drinks;
this.hasPreExistingCondition = hasPreExistingCondition;
this.gender = gender;
}
if (smokes) {
basePremium += 2000;
}
if (drinks) {
basePremium += 1500;
}
if (hasPreExistingCondition) {
basePremium += 2500;
}
return basePremium;
}
package insurancepremium;
import java.util.Scanner;
scanner.close();
}
BMICalculator:
package bmical;
MaleBMICalculator:
package bmical;
@Override
public String getBMISuggestion() {
if (bmi < 18.5) {
return "You are underweight. It's important to eat a balanced diet and consult with
a healthcare provider.";
} else if (bmi >= 18.5 && bmi < 24.9) {
return "You have a normal weight. Keep up the good work maintaining a healthy
lifestyle!";
} else if (bmi >= 25 && bmi < 29.9) {
return "You are overweight. Consider a balanced diet and regular exercise to
improve your health.";
} else {
return "You are obese. It's important to seek advice from a healthcare provider for
a suitable plan to improve your health.";
}
}
FemaleBMICalculator:
package bmical;
@Override
public String getBMISuggestion() {
if (bmi < 18.5) {
return "You are underweight. It's important to eat a balanced diet and consult with
a healthcare provider.";
} else if (bmi >= 18.5 && bmi < 24.9) {
return "You have a normal weight. Keep up the good work maintaining a healthy
lifestyle!";
} else if (bmi >= 25 && bmi < 29.9) {
return "You are overweight. Consider a balanced diet and regular exercise to
improve your health.";
} else {
return "You are obese. It's important to seek advice from a healthcare provider for
a suitable plan to improve your health.";
}
}
ChildBMICalculator:
package bmical;
BMICalculatorMain:
package bmical;
import java.util.Scanner;
BMICalculator bmiCalculator;
scanner.close();
}
UnitConverter
package unitconvertor;
LengthConverter:
package unitconvertor;
import java.util.Scanner;
@Override
public double convert(double value) {
Scanner scanner = new Scanner(System.in);
System.out.print("Convert (1) Meters to Feet or (2) Feet to Meters: ");
int choice = scanner.nextInt();
scanner.close();
if (choice == 1) {
return value * METER_TO_FEET;
} else {
return value / METER_TO_FEET;
}
DistanceConverter:
package unitconvertor;
import java.util.Scanner;
@Override
public double convert(double value) {
Scanner scanner = new Scanner(System.in);
System.out.print("Convert (1) Kilometers to Miles or (2) Miles to Kilometers: ");
int choice = scanner.nextInt();
scanner.close();
if (choice == 1) {
return value * KM_TO_MILES;
} else {
return value / KM_TO_MILES;
}
}
TemperatureConverter:
package unitconvertor;
import java.util.Scanner;
@Override
public double convert(double value) {
Scanner scanner = new Scanner(System.in);
System.out.print("Convert (1) Celsius to Fahrenheit or (2) Fahrenheit to Celsius: ");
int choice = scanner.nextInt();
scanner.close();
if (choice == 1) {
return (value * 9 / 5) + 32;
} else {
return (value - 32) * 5 / 9;
}
}}
WeightConverter:
package unitconvertor;
import java.util.Scanner;
@Override
public double convert(double value) {
Scanner scanner = new Scanner(System.in);
System.out.print("Convert (1) Kilograms to Pounds or (2) Pounds to Kilograms: ");
int choice = scanner.nextInt();
scanner.close();
if (choice == 1) {
return value * KILOGRAM_TO_POUND;
} else {
return value / KILOGRAM_TO_POUND;
}
}
UnitConversionMain:
package unitconvertor;
import java.util.Scanner;
UnitConverter converter;
switch(choice) {
case 1:
case 2:
converter = new WeightConverter();
break;
case 3:
converter = new TemperatureConverter();
break;
case 4:
converter = new DistanceConverter();
break;
default:
System.out.println("Invalid Choice");
return;
scanner.close();
}