Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
77 views

file1: Java Hands-On 1

This document contains code examples for calculating areas of shapes using Java classes and methods. It includes three files: 1) File1 defines an Area class with three methods to calculate the area of a circle given a radius, rectangle given length and width, and cuboid given height, length, and width. 2) File2 includes a main method that creates an Area object and calls the circle area method, printing the result. 3) File3 includes a main method that creates an Area object, prompts the user for height, length, and width, calls the cuboid area method, and prints the result. It also includes code examples for swapping names of two strings and checking if two email

Uploaded by

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

file1: Java Hands-On 1

This document contains code examples for calculating areas of shapes using Java classes and methods. It includes three files: 1) File1 defines an Area class with three methods to calculate the area of a circle given a radius, rectangle given length and width, and cuboid given height, length, and width. 2) File2 includes a main method that creates an Area object and calls the circle area method, printing the result. 3) File3 includes a main method that creates an Area object, prompts the user for height, length, and width, calls the cuboid area method, and prints the result. It also includes code examples for swapping names of two strings and checking if two email

Uploaded by

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

Java Hands-on 1

//file1

public class Area

public double calculateArea(double radius)

//PI*r*r area of circle

double p=3.1428571428571428571,area;

area=p*radius*radius;

return area;

public double calculateArea(double length,double width)

//area of rectangle

double area;

area=length*width;

return area;

public double calculateArea(double height,double length,double width)

//area of cuboid

double area;

area=2*(height*length+length*width+width*height);

return area;

}
//file2

public class Solution1

public static void main(String args[])

Area ar=new Area();

System.out.println(ar.calculateArea(14));

public class Solution2

public static void main(String args[])

Area ar=new Area();

System.out.println(ar.calculateArea(10.0,12.0));

//file3

import java.utils.Scanner;

public class Solution3

public static void main(String args[])

Area ar=new Area();

Scanner sc=new Scanner(System.in);

System.out.println("enter height");
double h=sc.nextDouble();

System.out.println("enter length");

double l=sc.nextDouble();

System.out.println("enter width");

double w=sc.nextDouble();

System.out.println(ar.calculateArea(h,l,w));

Java Hands-on 2

File1

public class Employee

Employee()

int id;

String name;

File2

public class Solution

public static String SwapName(String e1,String e2)


{

String temp=e1;

e1=e2;

e2=temp;

return (e1+" "+e2);

public static void main(String args[])

String e1="aaa";

String e2="bbb";

String r1=SwapName(e1,e2);

System.out.println(r1);

Java Hands-on 2

File1

File2
public class Solution
{
public static String checkEmail(String e1,String e2)
{
String name="gmail.com";
boolean r1=e1.endsWith("gmail.com");
boolean r2=e2.endsWith("gmail.com");
boolean r3=name.endsWith("gmail.com");
if(r1==r2==r3)
return "true";
else
return "false";

}
public static void main(String args[])
{
String e1="abc@rediff.com";
String e2="xyz@gmail.com";
System.out.println(checkEmail(e1,e2));
}
}

You might also like