Docsity

Class Comparison 2-Java Network Programming-Lab Manual, Exercises of Java Programming

Toggle sidebar
bg1
1. Create a class Student with following attributes
i. String name;
ii. int rollno;
iii. int age;
iv. String address;
v. String email;
b. Make these attributes public by writing keyword “public” before them
c. Write main method
d. Create two instances of Student class as
Student std1=new Student();
Student std2=new Student();
e. Initialize the data members of std1 students as
std1.name=”Jhone”;
std1.rollno=911;
std1.age=
std1.address=”Street 123 Block 4 City X Country Y”;
std1.email=[email protected];
Initialize the data members of std2 in the same way
f. Try printing these values;
2. Write code to compare the two students and print the name of the elder student
3. Enhance Student class and add the following method
public void bioData(){
System.out.println(“Name = “+name);
System.out.println(“Roll no = “+rollno);
System.out.println(“Age = “+age);
System.out.println(“Address = “+address);
}
4. Display the bio data of two students by calling the function bioData()
5. Enhance student class and add a function showMarks() that will print the marks obtained
in various subject
6. Write a class Circle define attributes and add the following methods
a. showRadius() //displays the radius of the circle
b. showArea() //displays area of the circle
c. showCenter() //displays x and y co-ordinates of the center of the circle
7. Write a program that
a. creates three circles
b. initializes them with suitable values
c. prints them in ascending order according to their areas.
Java Programming Day-01
Lab-session-02
Docsity.com

Partial preview of the text

Download Class Comparison 2-Java Network Programming-Lab Manual and more Exercises Java Programming in PDF only on Docsity!

  1. Create a class Student with following attributes i. String name; ii. int rollno; iii. int age; iv. String address; v. String email; b. Make these attributes public by writing keyword “ public” before them c. Write main method d. Create two instances of Student class as Student std1=new Student(); Student std2=new Student(); e. Initialize the data members of std1 students as std1.name=”Jhone”; std1.rollno=911; std1.age= std1.address=”Street 123 Block 4 City X Country Y”; [email protected]; Initialize the data members of std2 in the same way f. Try printing these values;
  2. Write code to compare the two students and print the name of the elder student
  3. Enhance Student class and add the following method public void bioData(){ System.out.println(“Name = “+name); System.out.println(“Roll no = “+rollno); System.out.println(“Age = “+age); System.out.println(“Address = “+address); }
  4. Display the bio data of two students by calling the function bioData()
  5. Enhance student class and add a function showMarks() that will print the marks obtained in various subject
  6. Write a class Circle define attributes and add the following methods a. showRadius() //displays the radius of the circle b. showArea() //displays area of the circle c. showCenter() //displays x and y co-ordinates of the center of the circle
  7. Write a program that a. creates three circles b. initializes them with suitable values c. prints them in ascending order according to their areas.

Java Programming Day- 01

Lab-session- 02

Docsity.com