0% found this document useful (0 votes)
10 views4 pages

Slip 15

Uploaded by

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

Slip 15

Uploaded by

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

import java.io.

*;
import java.util.Scanner;

public class FileCopy {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Accept the names of the two files


System.out.print("Enter the name of the source file (first file): ");
String sourceFileName = scanner.nextLine();

System.out.print("Enter the name of the destination file (second file): ");


String destFileName = scanner.nextLine();

// Create file objects for both source and destination files


File sourceFile = new File(sourceFileName);
File destFile = new File(destFileName);

// Check if the source file exists


if (!sourceFile.exists()) {
System.out.println("Source file does not exist.");
return;
}

// Try with resources to handle file operations (auto-closing resources)


try (BufferedReader reader = new BufferedReader(new
FileReader(sourceFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(destFile)))
{

String line;
// Read the content from the source file line by line and write to the
destination file
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine(); // Add a newline after each line
}

System.out.println("File copied successfully!");

} catch (IOException e) {
System.out.println("An error occurred while copying the file: " +
e.getMessage());
} finally {
scanner.close();
}
}
}
// Base class Account
class Account {
protected String custname; // Customer name
protected int accno; // Account number

// Default constructor
public Account() {
this.custname = "Unknown";
this.accno = 0;
}

// Parameterized constructor
public Account(String custname, int accno) {
this.custname = custname;
this.accno = accno;
}

// Method to display basic account details


public void displayAccountDetails() {
System.out.println("Customer Name: " + custname);
System.out.println("Account Number: " + accno);
}
}

// Subclass SavingAccount that extends Account


class SavingAccount extends Account {
protected double savingbal; // Savings balance
protected double minbal; // Minimum balance

// Default constructor
public SavingAccount() {
super();
this.savingbal = 0.0;
this.minbal = 500.0; // Default minimum balance
}

// Parameterized constructor
public SavingAccount(String custname, int accno, double savingbal, double
minbal) {
super(custname, accno); // Call to the parent class constructor
this.savingbal = savingbal;
this.minbal = minbal;
}

// Method to display savings account details


public void displaySavingDetails() {
displayAccountDetails(); // Call to parent class method
System.out.println("Savings Balance: $" + savingbal);
System.out.println("Minimum Balance: $" + minbal);
}
}

// Subclass AccountDetail that extends SavingAccount


class AccountDetail extends SavingAccount {
private double depositamt; // Amount to deposit
private double withdrawalamt; // Amount to withdraw
// Default constructor
public AccountDetail() {
super();
this.depositamt = 0.0;
this.withdrawalamt = 0.0;
}

// Parameterized constructor
public AccountDetail(String custname, int accno, double savingbal, double
minbal, double depositamt, double withdrawalamt) {
super(custname, accno, savingbal, minbal); // Call to parent class
constructor
this.depositamt = depositamt;
this.withdrawalamt = withdrawalamt;
}

// Method to deposit an amount


public void deposit() {
savingbal += depositamt;
System.out.println("Amount Deposited: $" + depositamt);
System.out.println("Updated Savings Balance: $" + savingbal);
}

// Method to withdraw an amount


public void withdraw() {
if (savingbal - withdrawalamt >= minbal) {
savingbal -= withdrawalamt;
System.out.println("Amount Withdrawn: $" + withdrawalamt);
System.out.println("Updated Savings Balance: $" + savingbal);
} else {
System.out.println("Insufficient balance! Minimum balance of $" +
minbal + " must be maintained.");
}
}

// Method to display full account details


public void displayAccountDetail() {
displaySavingDetails(); // Call to parent class method
System.out.println("Deposit Amount: $" + depositamt);
System.out.println("Withdrawal Amount: $" + withdrawalamt);
}
}

// Main class to test the AccountDetail functionality


public class Main_account {
public static void main(String[] args) {
// Creating an object of AccountDetail class with parameterized constructor
AccountDetail acc1 = new AccountDetail("John Doe", 12345, 1000.0, 500.0,
200.0, 300.0);

// Displaying account details before any operations


System.out.println("Account Details before Transactions:");
acc1.displayAccountDetail();

// Deposit operation
System.out.println("\nPerforming Deposit:");
acc1.deposit();
// Withdrawal operation
System.out.println("\nPerforming Withdrawal:");
acc1.withdraw();

// Displaying account details after operations


System.out.println("\nAccount Details after Transactions:");
acc1.displayAccountDetail();
}
}

You might also like