0% found this document useful (0 votes)
19 views6 pages

Java Second Exam in Jspider

Uploaded by

Ankita Halder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views6 pages

Java Second Exam in Jspider

Uploaded by

Ankita Halder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JAVA SECOND EXAM IN JSPIDER

1. Write java program to define object for Car with below attributes

1. Brand name

2. Engine type

3. Fuel type

4. Seating capacity

5. Model

Read the values from keyboard to create the object

2. Write java program to instantiate(create) an object customer.

Decide attributes yourself and read the values from keyboards

3. A student wants to enroll a course in Jspiders

Information required for rolling to course is

Student name

Degree

Email

Phone

Students can enroll either with phone number or email I’d

4. Write a java program to print the character is alpha ,numeric or special char.

5.Write a java program to check given year is leap year or not.


****) import java.util.*;
class Car {

String brandname;
String enginetype;
String fueltype;
String seating_capacity;
String model;

Car(String brandname,String enginetype,String fueltype,String


seating_capacity,String model){

this.brandname=brandname;
this.enginetype=enginetype;
this.fueltype=fueltype;
this.seating_capacity=seating_capacity;
this.model=model;
}
void details() {
System.out.println("brandname is:"+brandname+"enginetype
is:"+enginetype+"fuletype is:"+fueltype+"seating_capacity
is:"+seating_capacity);
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("brandname is:");
String ebrandname=sc.next();
System.out.println("enginetype is:");
String eenginetype=sc.next();
System.out.println("fueltype is:");
String efueltype=sc.next();
System.out.println("seating_capacity of:");
String eseating_capacity=sc.next();
System.out.println("model is:");
String emodel=sc.next();

Car c1=new
Car(ebrandname,eenginetype,efueltype,eseating_capacity,emodel);
c1.details();
}}

(===============================================================)

****) import java.util.Scanner;

class Customerdetails {

String fullname;
char gender;
long mobile_no;
String email_id;
String location;

Customerdetails(String fullname,char gender,long mobile_no,String


email_id,String location)
{
this.fullname=fullname;
this.gender=gender;
this.mobile_no=mobile_no;
this.email_id=email_id;
this.location=location;
}

void display()
{
System.out.println("fullname: "+fullname+", gender: "+gender+",
mobile_no: "+mobile_no+", email_id: "+email_id+" , location: "+location);
}

public static void main(String[] args) {


Scanner sc1 = new Scanner (System.in);
System.out.println("Enter fullname:");
String fname =sc1.nextLine();
System.out.println("Enter mobile_no");
long mobno =sc1.nextLong();
System.out.println("enter gender");
char ftype= sc1.next().charAt(0);
System.out.println("enter emailid:");
String em=sc1.next();
System.out.println("Enter location ");
String loc= sc1.next();

Customerdetails c1= new Customerdetails(fname, ftype, mobno, em, loc);


c1.display();
}
}

(===============================================================)

****) import java.util.*;

class Information {

String studentname;
String degree;
String email;
long phoneno;

Information(String studentname,String degree,String email){


this.studentname=studentname;
this.degree=degree;
this.email=email;
}
Information(String studentname,String degree,long phoneno){
this.studentname=studentname;
this.degree=degree;
this.phoneno=phoneno;
}
void details() {
System.out.println("studentname is:"+studentname+"degree which
have:"+degree+"email is:"+email+"phoneno is:"+phoneno);
}

public static void main(String[] args) {


Scanner sc=new Scanner(System.in);
System.out.println("print e for given value is email:");
System.out.println("print p for given value is phone number:");
char c=sc.next().charAt(0);
if(c=='e') {
System.out.println("student name is:");
String estudentname=sc.next();
System.out.println("degree ehich have is:");
String edegree=sc.next();
System.out.println("emailid is:");
String eemail=sc.next();

Information i1=new
Information(estudentname,edegree,eemail);
i1.details();
}
else if(c=='p') {
System.out.println("student name is:");
String estudentname=sc.next();
System.out.println("degree ehich have is:");
String edegree=sc.next();
System.out.println("phonr number is:");
long ephoneno=sc.nextLong();

Information i2=new
Information(estudentname,edegree,ephoneno);
i2.details();
}
else {
System.out.println("invalid input");
}
}
}

(===============================================================)
import java.util.Scanner;
public class Character {

public static void main(String[] args) {


Scanner sc = new Scanner (System.in);
System.out.print("Enter character: ");
char ch=sc.next().charAt(0);
if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z')){
System.out.println(ch+" character is alphabet");
}else if(ch>='0' && ch<='9'){
System.out.println(ch+" character is numeric");
}else{
System.out.println(ch + " character is special char");
}

}
}
(===============================================================)
import java.util.Scanner;
public class Leapyear {

public static void main(String[] args) {


Scanner sc1= new Scanner(System.in);
System.out.println("Enter the year or century");
int n= sc1.nextInt();
if((n%4==0&&n%100!=0)||(n%400==0)){
System.out.println("Leap year");
}
else{
System.out.println("not leap year");
}

}
}
(===============================================================)

You might also like