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

Java Programs- Methods and Constructors

The document outlines various Java programs that demonstrate the use of methods and constructors across different classes. Key examples include calculating summations, car pricing based on fuel type, cake rates, banking operations, salary calculations, product discounts, and geometric volume calculations. Additionally, it covers classes for movie ratings, railway ticket pricing, travel costs, and library fines, each with specified instance variables and member methods.

Uploaded by

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

Java Programs- Methods and Constructors

The document outlines various Java programs that demonstrate the use of methods and constructors across different classes. Key examples include calculating summations, car pricing based on fuel type, cake rates, banking operations, salary calculations, product discounts, and geometric volume calculations. Additionally, it covers classes for movie ratings, railway ticket pricing, travel costs, and library fines, each with specified instance variables and member methods.

Uploaded by

vidush673
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

JAVA PROGRAMS- METHODS AND CONSTRUCTORS

1) WAJP to find summation: 1! + 3! + 5! +.......until 'n' terms


2) WAJP to calculate price, based on model and fuel type.
Class name: Car
Member methods: imput(), calc(), display()
Fuel type Model Price
Diesel A1 800,000
A2 1,000,000
A3 1,500,000
Petrol A1 500,000
A2 900,000
A3 1,200,000
3) WAJP to display the rate of cake
Class name: Cake
Instance variables: flav, weit, price, shape
Memeber methods: input(), calc(), display()
Flavour Weight Rate
Black forest 500 400
1000 850
2000 1400\
White forest 500 350
1000 780
2000 1550

1) Classname- Bank
Instance variables- cname, acno, bal, ttype
memeber methods: input(), deposit(int amt), withdraw(int amt) [minimum
balance of 500 rupees to be there], showBalance(), display()
2) Classname- PaySlip
Instance variables- ename, sal, da [15%], hra [10%], pf [8%], fsal, ptax
Memeber methods: inputData(), calculation(), findTax(), output()
fsal= sal+da+hra-pf-ptax
Net Salary Tax%
10000-25000 12%
25001-55000 15%
55001-90000 18%
Above 90000 20%
3) Classname- Products
Instance variables- pname,price, qty, totalamt, dis
Memeber methods: readData(), calcData() -> totalamt= qty*price, show()
Totalamt Disc%
Upto 5000 0%
5001 to 10000 10%
10001 to 25000 15%
25001 to 50000 20%
Above 50000 25%

1) WAJP to find volumes of different shapes


Methodname- volume
Classname- VolumeOverload
1) Cone - 1/3 Pi r^2 h
2) Cuboid- l b h
3) Sphere- 4/3 Pi r^3
2) Classname- Patternoverloading
pattern() pattern(char ch) pattern(int n)
1 ch [n is limit]
12 chch 54321
123 chchch 4321
1234 chchchch 321
12345 chchchchch 21
1
3) Classname-Seriesoverloading
Series(int x, int n)- x+ x^2 + x^3 + x^4 + .....+ x^n
Series(int n) - 0,7,26,63,124.......'n'
Series() - 1/2 + 1/4 + 1/6 + ......+ 1/20
4) Classname- Patternoverloading1
Methodname: Pattern
pattern(int n) [n passed as 5] pattern(int n, char ch)
54321 Straight line of 'ch' and
5432 'n' as limit
543
54
5
5) Classname- PeriCal
perimeter(int s)- perimeter of square
perimeter(int l, int b)- perimeter of rectangle
perimeter(double r)- perimeter of circle

1) classname- MovieMagic
Inst: year, title, rating, lang, tamt, ramt, samt, no.t
MM: default constructor, findAmt(), input(), display()
Rating Print Tamt
0.0- 2.0 Flop 200
2.1-3.4 Semi Hit 350
3.5-4.5 Hit 500
4.6-5.0 Blockbuster 900

2) Classname- RailwayTicket
Inst: name, mobno, coach, amt, famt, not
MM: default and parameterized constructor, price(), display()
Coach Amt/Ticket
First AC 1200
Second AC 1100
Third AC 1000
Sleeper 900
General 700

3) Classname- Travels
Inst: cname, taxino, dist, ttl
MM: default constructor, input method, findTotal(), display()
Dist Rate/km
First 10 25
Next 20 20
Next 40 18
Above 70 15

4) Classname- Library
Inst: cname, bname, author, noday, fine, cno
MM: default and parameterized constructor, calculate(), display()
Nodays Rate/day
Less than 5 0
5-10 1.5
11-15 3.5
More than 15 5

You might also like