Professional Documents
Culture Documents
ID: B161753
WEEK-5
/*
1. Write a Java Program to implement Wrapper classes and their methods.
*/
package labmanual.week5;
public class Q1 {
public static void main(String[] args) {
// create primitive types
int a = 5;
double b = 5.54;
/*
2. Write an application that prompts the user for the radius of a circle and uses a method
called circleArea to calculate the area of the circle and uses a method circlePerimeter to
calculate the perimeter of the circle.
*/
package labmanual.week5;
import java.util.Scanner;
public class Q2 {
public double circleArea(double radius) {
return Math.PI * radius * radius;
}
/*
3. Write a JAVA program for the following a. Call by Value b. Call by Object
*/
package labmanual.week5;
public class Q3 {
/*
Create a class Account with an instance variable balance (double). It should contain a
constructor that initializes the balance, ensure that the initial balance is greater than 0.0.
Acct details: Acct_Name, Acct_acctno, Acct_Bal, Acct_Address.
Create two methods namely credit and debit, getBalance. The Credit adds the amount
(passed as parameter) to balance and does not return any data. Debit method withdraws
money from an Account. GetBalance displays the amount. Ensure that the debit amount
does not exceed the Account’s balance. In that case the balance should be left unchanged
and the method should print a message indicating
“Debit amount exceeded account
balance”
*/
package labmanual.week5;
import java.util.Scanner;
class AccountDemo {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Account account1 = new Account(1000.0, "sameer sbi account", 1, "hyderabad");
Account account2 = new Account(12000.0, "roy andhra bank account", 34, "new york");
/*
5. Write Java program for the following
a. Example for this operator and the use of this keyword.
b. Example for super keyword.
c. Example for static variables and methods.
*/
package labmanual.week5;
class Person {
int id;
String name;
class StaticDemo {
static int x = 19; // static variable alongside initialization
static int y; // declaration of static variable
// static method
static void func(int z) {
System.out.println("x = " + x);
System.out.println("y = " + y);
System.out.println("z = " + z);
}
// static block
static {
System.out.println("Running static block");
y = x + 100;
}
}
public class Q5 {
public static void main(String[] args) {
// demonstration of this keyword
new Student1(111, "ankit", 5000f).display(); // displays incorrect information as it fails to assign values
new Student2(111, "ankit", 5000f).display(); // displays correct information