Java
Java
Account.java
public class Account {
private long accountNumber;
private double balanceAmount;
return false;
}
}
Main.java
import java.text.DecimalFormat;
import java.util.Scanner;
if (!isWithdrawn) {
System.out.println("Insufficient balance");
}
Numerology number
Main.java
import java.util.Scanner;
return sum;
}
while (string.length() != 1) {
string = String.valueOf(getSum(Long.parseLong(string)));
}
return Integer.parseInt(string);
}
return oddCount;
}
return evenCount;
}
System.out.println("Sum of digits");
System.out.println(getSum(num));
System.out.println("Numerology number");
System.out.println(getNumerology(num));
if (Character.isLowerCase(ch)) {
int sub = (int) ch - 7;
stringBuilder.append(ch);
} else if (Character.isWhitespace(ch)) {
stringBuilder.append(ch);
}
}
if (flag) {
System.out.println("Decrypted text:");
System.out.println(stringBuilder.toString());
} else {
System.out.println("No hidden message");
}
}
}
CurrentAccount.java
public class CurrentAccount extends Account implements MaintenanceCharge {
public CurrentAccount(String accountNumber, String customerName, double balance) {
super(accountNumber, customerName, balance);
}
@Override
public float calculateMaintenanceCharge(float noOfYears) {
return (100.0f + noOfYears) + 200.0f;
}
}
MaintenanceCharge.java
public interface MaintenanceCharge {
float calculateMaintenanceCharge(float noOfYears);
}
SavingsAccount.java
public class SavingsAccount extends Account implements MaintenanceCharge {
public SavingsAccount(String accountNumber, String customerName, double balance) {
super(accountNumber, customerName, balance);
}
@Override
public float calculateMaintenanceCharge(float noOfYears) {
return (50.0f * noOfYears) + 50.0f;
}
}
UserInterface.java
import java.text.DecimalFormat;
import java.util.Scanner;
switch (choice) {
case 1: {
SavingsAccount savingsAccount = new SavingsAccount(accountNumber,
customerName, balance);
System.out.println("Maintenance Charge for Savings Account is Rs " +
decimalFormat.format(savingsAccount.calculateMaintenanceCharge(noOfYears)));
break;
}
case 2: {
CurrentAccount currentAccount = new CurrentAccount(accountNumber,
customerName, balance);
System.out.println("Maintenance Charge for Current Account is Rs " +
decimalFormat.format(currentAccount.calculateMaintenanceCharge(noOfYears)));
}
}
}
}
Batting Average
UserInterface.java
package com.ui;
import com.utility.Player;
import java.util.ArrayList;
import java.util.Scanner;
while (flag) {
System.out.println("1. Add Runs Scored");
System.out.println("2. Calculate average runs scored");
System.out.println("3. Exit");
System.out.println("Enter your choice");
int choice = scanner.nextInt();
switch (choice) {
case 1: {
System.out.println("Enter the runs scored");
int score = scanner.nextInt();
player.addScoreDetails(score);
break;
}
case 2: {
System.out.println("Average runs secured");
System.out.println(player.getAverageRunScored());
break;
}
case 3: {
System.out.println("Thank you for use the application");
flag = false;
break;
}
}
}
}
}
Player.java
package com.utility;
import java.util.List;
Grade Calculation
Main.java
import java.util.Scanner;
@Override
public void run() {
int totalMarks = 0;
@Override
public String toString() {
return id;
}
@Override
public int compareTo(Employee employee) {
return this.id.compareTo(employee.getId());
}
}
try {
LocalDate joiningDate = LocalDate.parse(joiningDateStr, dateTimeFormatter);
Employee employee = new Employee(id, joiningDate);
employee.setIsEligible(now);
employees.add(employee);
} catch (Exception ignore) {
System.out.println("Invalid date format");
System.exit(0);
}
});
List<Employee> filteredEmployees =
employees.stream().filter(Employee::getIsEligible).collect(Collectors.toList());
if (filteredEmployees.isEmpty()) {
System.out.println("No one is eligible");
} else {
Collections.sort(filteredEmployees);
filteredEmployees.forEach(System.out::println);
}
}
}
NumberTypeUtility.java
import java.util.Scanner;
if (idOdd().checkNumber(num)) {
System.out.println(num + " is odd");
} else {
System.out.println(num + " is not odd");
}
}
}
DB.java
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class DB {
//ENSURE YOU DON'T CHANGE THE BELOW CODE WHEN YOU SUBMIT
public static Connection getConnection() throws ClassNotFoundException,
SQLException {
try{
FlightManagementSystem.java
import java.util.*;
import java.sql.*;
public class FlightManagementSystem{
public ArrayList<Flight> viewFlightsBySourceDestination(String source, String destination){
DB db=new DB();
ArrayList<Flight> list=new ArrayList<Flight>();
try{
int f=0;
Connection con=db.getConnection();
Statement st=con.createStatement();
String sql= "select * from Flight where source= '"+source+"' and destination=
'"+destination+"'";
ResultSet rs=st.executeQuery(sql);
while(rs.next()){
f=1;
Flight x=new Flight(rs.getInt(1), rs.getString(2),rs.getString(3), rs.getInt(4),
rs.getDouble(5));
list.add(x);
}
con.close();
if(f==1)
return list;
else
return null;
}
catch(SQLException e){
System.out.println("SQL Error. Contact Administrator.");
return null;
}
catch(Exception e){
System.out.println("Exception. Contact Administrator.");
return null;
}
}
}
Flight.java
Perform Calculation
import java.util.Scanner;
int a = sc.nextInt();
int b= sc.nextInt();
System.out.println("The difference is
"+Perform_subtraction.performCalculation(a,b));
return Perform_calculation;
}
return Perform_calculation;
return Perform_calculation;
float c = (float)a;
float d = (float)b;
return (c/d);
};
return Perform_calculation;
GD HOSPITAL
Payment Inheritance
Bill.java
public class Bill {
String message = "Payment not done and your due amount is "+obj.getDueAmount();
if(obj instanceof Cheque ) {
if(cheque.payAmount())
if(cash.payAmount())
if(card.payAmount())
return message;
Cash.java
public class Cash extends Payment{
this.cashAmount = cashAmount;
@Override
Cheque.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
this.dateOfIssue = dateOfIssue;
@Override
try {
Date issueDate = new SimpleDateFormat("dd-MM-yyyy").parse(date);
setDateOfIssue(issueDate);
}
catch (ParseException e) {
e.printStackTrace();
}
}
}
Credit.java
public class Credit extends Payment {
return creditCardNo;
this.creditCardNo = creditCardNo;
return cardType;
this.cardType = cardType;
return creditCardAmount;
@Override
int tax = 0;
switch(cardType) {
case "silver":
setCreditCardAmount(10000);
setCreditCardAmount(getCreditCardAmount()-tax);
isDeducted = true;
break;
case "gold":
setCreditCardAmount(50000);
setCreditCardAmount(getCreditCardAmount()-tax);
isDeducted = true;
}
break;
case "platinum":
setCreditCardAmount(100000);
setCreditCardAmount(getCreditCardAmount()-tax);
isDeducted = true;
break;
return isDeducted;
Main.java
import java.util.Scanner;
switch (mode) {
case "cash":
cash.setCashAmount(cashAmount);
cash.setDueAmount(dueAmount);
System.out.println(bill.processPayment(cash));
break;
case "cheque":
cheque.setChequeAmount(chequeAmount);
cheque.setChequeNo(number);
cheque.generateDate(date);
cheque.setDueAmount(dueAmount);
System.out.println(bill.processPayment(cheque));
break;
case "credit":
credit.setCardType(cardType);
credit.setCreditCardNo(creditNumber);
credit.setDueAmount(dueAmount);
System.out.println(bill.processPayment(credit));
default:
break;
sc.close();
Payment.java
public class Payment {
return dueAmount;
}
this.dueAmount = dueAmount;
return false;
HUNGER EATS
package com.utility;
import java.util.*;
import com.bean.FoodProduct;
public class Order{
private double discountPercentage;
private List<FoodProduct> foodList=new ArrayList<FoodProduct>();
}
// System.out.println(bill);
// System.out.println(dis);
bill=bill-((bill*discountPercentage)/100);
return bill;
}
}
package com.ui;
import java.util.Scanner;
import com.utility.Order;
import com.bean.FoodProduct;
for(int i=0;i<itemno;i++)
{
FoodProduct fd=new FoodProduct();
System.out.println("Enter the item id");
fd.setFoodId(sc.nextInt());
System.out.println("Enter the item name");
fd.setFoodName(sc.next());
System.out.println("Enter the cost per unit");
fd.setCostPerUnit(sc.nextDouble());
System.out.println("Enter the quantity");
fd.setQuantity(sc.nextInt());
o.addToCart(fd);
}
}
package com.bean;
Singapore
import java.util.*;
public class tourism {
static String name;
static String place;
static int days;
static int tickets;
static double price = 0.00;
static double total = 0.00;
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Enter the passenger name");
name = in.nextLine();
System.out.println("Enter the place name");
place=in.nextLine();
if(place.equalsIgnoreCase("beach")
||place.equalsIgnoreCase("pilgrimage")||place.equalsIgnoreCase("heritage")||place.equalsIgno
reCase("Hills")||place.equalsIgnoreCase("palls")||place.equalsIgnoreCase("adventure")){
System.out.println("Enter the number of days");
days = in.nextInt();
if(days>0){
System.out.println("Enter the number of Tickets");
tickets = in.nextInt();
if(tickets>0){
if(place.equalsIgnoreCase("beach")){
price = tickets*270;
if(price>1000){
total = 85*price/100;
System.out.printf("Price:%.2f",total);
}
else {
System.out.printf("Price:%.2f",price);
}
}
else if(place.equalsIgnoreCase("prilgrimage")){
price = tickets*350;
if(price>1000){
total = 85*price/100;
System.out.printf("Price:%.2f",total);
}
else {
System.out.printf("Price:%.2f",price);
}
}
else if(place.equalsIgnoreCase("heritage")){
price = tickets*430;
if(price>1000){
total = 85*price/100;
System.out.printf("Price:%.2f",total);
}
else {
System.out.printf("Price:%.2f",price);
}
}
else if(place.equalsIgnoreCase("hills")){
price = tickets*780;
if(price>1000){
total = 85*price/100;
System.out.printf("Price:%.2f",total);
}
else {
System.out.printf("Price:%.2f",price);
}
}
else if(place.equalsIgnoreCase("palls")){
price = tickets*1200;
if(price>1000){
total = 85*price/100;
System.out.printf("Price:%.2f",total);
}
else {
System.out.printf("Price:%.2f",price);
}
}
else {
price = tickets*4500;
if(price>1000){
total = 85*price/100;
System.out.printf("Price:%.2f",total);
}
else {
System.out.printf("Price:%.2f",price);
}
}
}
else{
System.out.println(tickets+" is an Invalid no. of tickets");
}
}
else{
System.out.println(days+" is an Invalid no. of days");
}
}
else {
System.out.println(place+" is an Invalid place");
}
}
}
Prime no ending
import java.util.*;
public class Main
{
public static void main (String[] args) {
int flag=0, k=0, z=0;
Scanner sc =new Scanner(System.in );
System.out.println("Enter the first number");
int f=sc.nextInt();
System.out.println("Enter the last number");
int l=sc.nextInt();
for(int i=f; i<=l; i++)
{
for(int j=2; j<i; j++)// this loop increments flag if i is divisible by j
{
if(i%j==0)
{
flag++;
}
}
if(i==l && (flag!=0 || i%10!=1))//when last number is not a prime
{
while(z==0)
{
for(int a=2; a<i; a++)
{
if(i%a==0)
{
flag++;
}
}
if(i%10==1 && flag==0)
{
System.out.print(","+i);
z++;
}
flag=0;
i++;
}
}
if(i%10==1 && flag==0)//to check for last digit 1 and prime
{
if(k==0)
{
System.out.print(i);
k++;
}
else
{
System.out.print(","+i);
}
}
flag=0;
}
}
}
Query Set
public class Query {
import java.util.Scanner;
public class TestApplication {
public static void main(String[] args) {
Query query = new Query();
Scanner sc = new Scanner(System.in);
Query.DataSet primary = query.new DataSet();
Query.DataSet secondary = query.new DataSet();
System.out.println("Enter the Details of primary data set");
System.out.println("Enter the theatre id");
String theatreid = sc.next();
primary.setTheatreId(theatreid);
sc.nextLine();
System.out.println("Enter the theatre name");
String theatrename = sc.next();
primary.setTheatreName(theatrename);
sc.nextLine();
System.out.println("Enter the location");
String location = sc.next();
primary.setLocation(location);
sc.nextLine();
System.out.println("Entrer the no of screens");
int screens = sc.nextInt();
primary.setNoOfScreen(screens);
System.out.println("Ente the ticket cost");
double cost = sc.nextDouble();
primary.setTicketCost(cost);
System.out.println("ENter the details of secondary data set");
System.out.println("Enter the theatre id");
theatreid = sc.next();
secondary.setTheatreId(theatreid);
sc.nextLine();
System.out.println("Enter the theatre name");
theatrename = sc.next();
secondary.setTheatreName(theatrename);
sc.nextLine();
System.out.println("Enter the location");
location = sc.next();
secondary.setLocation(location);
sc.nextLine();
System.out.println("Entrer the no of screens");
screens = sc.nextInt();
secondary.setNoOfScreen(screens);
System.out.println("Ente the ticket cost");
cost = sc.nextDouble();
secondary.setTicketCost(cost);
System.out.println("Enter the query id");
String queryid = sc.next();
query.setQueryId(queryid);
sc.nextLine();
System.out.println("Enter the query category");
String querycategory = sc.next();
query.setQueryCategory(querycategory);
sc.nextLine();
query.setPrimaryDataset(primary);
query.setSecondaryDataSet(secondary);
System.out.println(query);
}
}
Extract book
import java.util.Scanner;
class ExtractBook {
switch (code) {
case 101:
return "Accounting";
case 102:
return "Economics";
case 103:
return "Engineering";
}
try {
int dCode = extractDepartmentCode(str);
String dString = extractDepartmentName(dCode);
int year = extractDate(str);
int pages = extractNumberOfPages(str);
String bookId = extractBookId(str);
} catch (Error e) {
System.out.println(e.getMessage());
}
}
Fixed deposit
import java.util.*;
class FDScheme {
Annual Salary
import java.io.*;
public class Main
{
public static void main(String[] args)throws IOException
{
// Scanner sc=new Scanner(System.in);
//Fill the code
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Employee Name");
String name=br.readLine();
System.out.println("Enter percentage of salary");
double percent=Double.parseDouble(br.readLine());
if(percent>0&&percent<20)
{
System.out.println("Enter the Year of Experience");
int time=Integer.parseInt(br.readLine());
if(time>0&&time<15)
{
double permonth=12000+(2000*(time));
double dayshift=permonth*6;
double nightshift=(((permonth*percent)/100)+permonth)*6;
double annualIncome=dayshift+nightshift;
}
else{
System.out.println((int)time+" is an invalid year of experience");}
}
else
System.out.println((int)percent+" is an invalid percentage");
}
}
Amity Passenger
import java.util.*;
public class PassengerAmenity {
if(no>0)
{
String name[]=new String[no];
String seat[]=new String[no];
String arr[]=new String[no];
for(int i=0;i<no;i++)
{
System.out.println("Enter the name of the passenger "+(i+1));
String str=sc.nextLine();
name[i]=str.toUpperCase();
int r=Integer.parseInt(seat[i].substring(1,seat[i].length()));
else
{
System.out.println(r+" is invalid seat number");
break;
}
}
else
{
System.out.println(seat[i].charAt(0)+" is invalid coach");
break;
}
arr[i]=name[i]+" "+seat[i];
}
if(count==seat.length)
{
Arrays.sort(seat);
for(int i=seat.length-1;i>=0;i--)
{
for(int j=0;j<arr.length;j++)
{
if(arr[j].contains(seat[i]))
{
System.out.println(arr[j]);
}
}
}
}
}
else
{
System.out.println(no+" is invalid input");
}
}
Club Member
import java.util.Scanner;
this.membershipFees=(double) 50000.0;
}
else if(!(memberType=="Premium"))
{
this.membershipFees=(double) 75000.0;
}
System.out.println("Member Id is "+this.memberId);
System.out.println("Member Name is "+this.memberName);
System.out.println("Member Type is "+this.memberType);
System.out.println("Membership Fees is "+this.membershipFees);
}
}