SET A
1. Using javap, view the methods of the following classes from the lang package: java.lang.Object , java.lang.String and java.util.Scanner.
2. Compile sample program 2. Type the following command and view the bytecodes. javap -c MyClass
SET B
1. Write a java program to display the system date and time in various formats shown below:
Current date is : 31/07/2015
Current date is : 07-31-2015
Current date is : Friday July 31 2015
Current date and time is : Fri July 31 16:25:56 IST 2015
Current date and time is : 31/07/15 16:25:56 PM +0530
Current time is : 16:25:56
Current week of year is : 31
Current week of month : 5
Current day of the year is : 212
Note: Use java.util.Date and java.text.SimpleDateFormat class
2. Define a class MyNumber having one private int data member. Write a default constructor to initialize it to 0 and another constructor to initialize it to a value (Use this). Write methods isNegative, isPositive, isZero, isOdd, isEven. Create an object in main. Use command line arguments to pass a value to the object (Hint : convert string argument to integer) and perform the above tests. Provide javadoc comments for all constructors and methods and generate the html help file.
1. Using javap, view the methods of the following classes from the lang package: java.lang.Object , java.lang.String and java.util.Scanner.
2. Compile sample program 2. Type the following command and view the bytecodes. javap -c MyClass
SET B
1. Write a java program to display the system date and time in various formats shown below:
Current date is : 31/07/2015
Current date is : 07-31-2015
Current date is : Friday July 31 2015
Current date and time is : Fri July 31 16:25:56 IST 2015
Current date and time is : 31/07/15 16:25:56 PM +0530
Current time is : 16:25:56
Current week of year is : 31
Current week of month : 5
Current day of the year is : 212
Note: Use java.util.Date and java.text.SimpleDateFormat class
2. Define a class MyNumber having one private int data member. Write a default constructor to initialize it to 0 and another constructor to initialize it to a value (Use this). Write methods isNegative, isPositive, isZero, isOdd, isEven. Create an object in main. Use command line arguments to pass a value to the object (Hint : convert string argument to integer) and perform the above tests. Provide javadoc comments for all constructors and methods and generate the html help file.
3 Comments
Assignment 1 set C please ... thanks for this stuff.. great work man...
ReplyDeleteImmediately nedd this Set B2
DeleteSlip 3_2: Define a class patient (patient_name, patient_age,
ReplyDeletepatient_oxy_level,patient_HRCT_report). Create an object of patient. Handle
appropriate exception while patient oxygen level less than 95% and HRCT scan
report greater than 10, then throw user defined Exception “Patient is Covid Positive(+)
and Need to Hospitalized” otherwise display its information.
import java.io.*;
class CovidException extends Exception{
public CovidException(){
System.out.println("Patient is Covid Positive and needs to be hospitalized");
}
}
class Patient{
String name;
int age;
double level,hrct;
public Patient(String name,int age,double level,double hrct)
{
this.name=name;
this.age=age;
this.level=level;
this.hrct=hrct;
}
public static void main(String[] args)throws IOException
{
String name;
int age;
double level,hrct;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter name: ");
name=br.readLine();
System.out.println("Enter the age: ");
age=Integer.parseInt(br.readLine());
System.out.println("Oxygen level: ");
level=Double.parseDouble(br.readLine());
System.out.println("HRCT report: ");
hrct=Double.parseDouble(br.readLine());
Patient ob=new Patient(name,age,level,hrct);
try{
if(ob.level<95 && ob.hrct>10)
throw new CovidException();
else
System.out.println("Patient Info: \n"+"Name: "+ob.name+"\nAge: "+ob.age+"\nHRCT
report: "+ob.hrct+"\nOxygen level:"
+ob.level);
}catch(CovidException e){
}
}
}