0% found this document useful (0 votes)
4 views

exp1 sess2

The document outlines a programming assignment involving the creation of classes and objects in Java, specifically for a bank account and a movie information system. It includes detailed problem statements, program structures, and methods for handling user inputs and displaying information. The document also indicates that there are additional programs (Program 3 and Program 4) that are not detailed.

Uploaded by

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

exp1 sess2

The document outlines a programming assignment involving the creation of classes and objects in Java, specifically for a bank account and a movie information system. It includes detailed problem statements, program structures, and methods for handling user inputs and displaying information. The document also indicates that there are additional programs (Program 3 and Program 4) that are not detailed.

Uploaded by

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

Name: Nisarg Anand Chhoda

UID: 2024200020

Experiment No. 1 (session 2)

AIM: Write a program to demonstrate classes and objects

Program 1

PROBLEM Define a class to represent a bank account. Include the


STATEMENT : following members:
Data members
a. Name of the depositor
b. Account number
c. Type of account
d. Balance amount in the account
Member functions
a. To assign initial value
b. To deposit an amount
c. To withdraw an amount after checking the balance
d. To display name and balance Write a main method to test
the program.

PROGRAM: import java.util.Scanner;

class Bank {
String name, acctype;
long Accnum;
float balance, amount;

void printInitial() {
System.out.println("Depositor name: " + name);
System.out.println("Account number: " + Accnum);
System.out.println("Account type: " + acctype);
System.out.println("Initial balance: " + balance);
}

void printDeposit() {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the amount to be deposited: ");
amount = scan.nextFloat();
balance=balance+amount;
System.out.println("Updated balance: " + balance);
}

void printWithdraw() {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the amount to be withdrawn: ");
amount = scan.nextFloat();
if (amount > balance) {
System.out.println("Insufficient balance");
} else {
balance=balance-amount;
System.out.println("Updated balance: " + balance);
}
}

void printDetails() {
System.out.println("Account holder: " + name);
System.out.println("Account balance: " + balance);
}

void printBalance() {
System.out.println("Current balance: " + balance);
}
}

class TestBank {
public static void main(String[] args) {
Bank a = new Bank();
Scanner scan = new Scanner(System.in);

System.out.println("Enter depositor name: ");


a.name = scan.nextLine();

System.out.println("Enter account number: ");


a.Accnum = scan.nextLong();

scan.nextLine();
System.out.println("Enter account type: ");
a.acctype = scan.nextLine();

System.out.println("Enter initial balance: ");


a.balance = scan.nextFloat();

a.printInitial();

System.out.println("\nSelect one of the following operations:");


System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Check balance");

int k = scan.nextInt();

if (k == 1) {
a.printDeposit();
} else if (k == 2) {
a.printWithdraw();
} else if (k == 3) {
a.printBalance();
} else {
System.out.println("Error! Please enter a valid option.");
}
}
}
RESULT:

Program 2

PROBLEM Write a program in Java to maintain the information of Movies


STATEMENT : which includes the information of :
1-name of movie
2- type of movie( action , thriller , comedy ,drama )
3- Hero name
4- Heroine
5- budget in Rs.
include method to
1- display this information
Q.1 Write a program to accept the information of movies from
user and display the same.
Q.2 Create two different objects of the same and Display the
movie name having highest budget.

PROGRAM: import java.util.Scanner;


class Movie {
String movieName, movieType, heroName, heroineName;
float budget;

void acceptDetails() {
Scanner scan = new Scanner(System.in);

System.out.println("Enter Movie Name: ");


movieName = scan.nextLine();

System.out.println("Enter Movie Type (Action, Thriller, Comedy,


Drama): ");
movieType = scan.nextLine();

System.out.println("Enter Hero Name: ");


heroName = scan.nextLine();

System.out.println("Enter Heroine Name: ");


heroineName = scan.nextLine();

System.out.println("Enter Movie Budget (in Rs.): ");


budget = scan.nextFloat();
}
void displayDetails() {
System.out.println("\nMovie Name: " + movieName);
System.out.println("Movie Type: " + movieType);
System.out.println("Hero Name: " + heroName);
System.out.println("Heroine Name: " + heroineName);
System.out.println("Budget (in Rs.): " + budget);
}

static Movie movieWithHighestBudget(Movie movie1, Movie


movie2) {
if (movie1.budget > movie2.budget) {
return movie1;
} else {
return movie2;
}
}
}
class MovieTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Movie movie1 = new Movie();
Movie movie2 = new Movie();
System.out.println("Enter details for Movie 1:");
movie1.acceptDetails();

System.out.println("\nEnter details for Movie 2:");


movie2.acceptDetails();

System.out.println("\nDetails of Movie 1:");


movie1.displayDetails();

System.out.println("\nDetails of Movie 2:");


movie2.displayDetails();
Movie highestBudgetMovie =
Movie.movieWithHighestBudget(movie1, movie2);
System.out.println("\nMovie with the highest budget:");
highestBudgetMovie.displayDetails();
}
}
RESULT:

Program 3

PROBLEM
STATEMENT:
PROGRAM:

RESULT:

Program 4

PROBLEM
STATEMENT:

PROGRAM:

RESULT:

CONCLUSION:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy