Tesktrpk$d
Tesktrpk$d
Tesktrpk$d
Aim: Write a java program for converting Pound into Rupees. (Accept Pounds from command line
argument and using scanner class also and take 1 Pound = 100 Rupees.)
Code:
import java.util.*;
class Cons{ ––
double r;
int p1=23;
public Cons(){
r=93.32*p1;
}
public Cons( int p){
r=93.32*p;
}
PRACTICAL 2
Aim: Write a program that defines TriangleArea class with three constructors.
The first form accepts no arguments. The second accept one double
value for radius. The third form accepts any two arguments
import java.util.*;
class TriangleArea{
double b;
int h;
public TriangleArea(){
b=10;
h=23;
System.out.println("area of triangle by default constructor " + b*h/2);
}
Output:
PRACTICAL 3
Aim: Create a class called Employee that includes three pieces of information as instance variables—a
first name (type String), a last name (type String) and a monthly salary (double). Your class should have a
constructor that initializes the three instance variables. Provide a set and a get method for each instance
variable. If the monthly salary is not positive, set it to 0.0. Write a test application named EmployeeTest
that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s
yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again.*/
code:
import java.util.*;
class EmployeeTest{
String s2,s3;
double d;
e1.setFname("luther");
e1.setLname("hargrives");
e1.setsal(23000.45);
s2=e1.getFname();
s3=e1.getLname();
d=e1.getsal();
if(d<0.0){
d=0.0;
}
System.out.println( "First name : " + s2 + " last name : " + s3 + " your salary :" + d);
e1.Apresal();
e2.setFname("klaus");
e2.setLname("hargrives");
e2.setsal(-24000.45);
s2=e2.getFname();
s3=e2.getLname();
d=e2.getsal();
if(d<0.0){
d=0.0;
}
System.out.println( "First name : " + s2 + " last name : " + s3 + " your salary : " + d);
class Employee{
String firstname;
String lastname;
double salary;
public Employee(){
firstname="";
lastname="";
salary=0.0;
}
public void setFname(String s1){
this.firstname=s1;
}
this.lastname=s1;
}
public void setsal(double s1){
this.salary=s1;
}
return this.firstname;
}
public String getLname(){
return this.lastname;
return this.salary;
Practical 4
/*Create a class called Date that includes three pieces of information as
instance variables—a month (type int), a day (type int) and a year (type
int). Your class should have a constructor that initializes the three
instance variables and assumes that the values provided are correct.
Provide a set and a get method for each instance variable. Provide a
method displayDate that displays the month, day and year separated by
forward slashes (/). Write a test application named DateTest that
demonstrates class Date’s capabilities.*/
class pate{
int year,month,day;
public pate(){
}
}
public void setD(int d){
this.day=d;
}
return month;
}
return day;
}
class Date{
d1.setY(2004);
d1.setM(11);
d1.setD(12);
d1.display();
}
5
/*Write a program to print the area of a rectangle by creating a class named
'Area' taking the values of its length and breadth as parameters of its
constructor and having a method named 'returnArea' which returns the
area of the rectangle. Length and breadth of rectangle are entered
through keyboard*/
class Area{
Area(){
this.l=len;
this.b=be;
a1.returnArea();
}
6
/*Print the sum, difference and product of two complex numbers by
creating a class named ‘Complex’ with separate methods for each
operation whose real and imaginary parts are entered by user*/
class complex{
int img,rel;
complex(){}
this.rel=r;
this.img=i;
}
public complex sum(complex c1,complex c2){
}
public complex mul(complex c1,complex c2){
//System.out.ptintln(" Sum of given complex numbers : " + c3.rel + " " + c3.img+ "i" );
//System.out.ptintln(" Sum of given complex numbers : " + c3.rel + " " + c3.img+ "i" );
return c3;
}
void display()
{
System.out.println(" answer complex numbers : " + rel + " " + img+ "i" );
}
}
class Complex1{
public static void main(String arg[]){
complex c1=new complex(2,3);
Fifth
/*Create a class 'Degree' having a method 'getDegree' that prints "I got a
degree". It has two subclasses namely 'Undergraduate' and 'Postgraduate'
each having a method with the same name that prints "I am an
Undergraduate" and "I am a Postgraduate" respectively. Call the method
by creating an object of each of the three classes*/
class degree{
public degree(){
void getDegree(){
d.getDegree();
u.getDegree();
p.getDegree();
}
}
public undergraduate(){
void getDegree(){
System.out.println("i am an undergraduate");
super();
}
}
class postgraduate extends degree{
public postgraduate()
{
void getDegree(){
System.out.println("i am a postgraduate");
super();
Sixth
/*Write a java that implements an interface AdvancedArithmetic which
contains amethod signature int divisor_sum(int n). You need to write a
class calledMyCalculator which implements the interface. divisorSum
function just takes an integer as input and return the sum of all its
divisors.
For example, divisors of 6 are 1, 2, 3 and 6, so divisor_sum should return
12. The value of n will be at most 1000*/
import java.util.*;
interface AdvancedArithmetic{
public six(){
}
public void divisor_sum(int n){
int c=0;
for(int i=1;i<=n;i++){
if(n%i==0){
c=c+i;
}
}
System.out.println(" your answer" + c);
}
c1.divisor_sum(k);
}
Seventh
/*Assume you want to capture shapes, which can be either circles (with a
radiusand a color) or rectangles (with a length, width, and color). You
also want to be able to create signs (to post in the campus center, for
example), each of which has a shape (for the background of the sign) and
the text (a String) to put on the sign. Create classes and interfaces for
circles, rectangles, shapes, and signs. Write a program that illustrates the
significance of interface default method.
*/
interface shape{
}
}
void sign1();
public rectangle(){
System.out.println(" 90 as rectangle");
}
class circle1 implements sign{
public circle1(){
System.out.println("45 is area circle");
}
public void sign1(){