Slip 10

 Q1) Write a program to find the cube of given number using functional interface. [10 marks] 

//@FunctionalInterface

interface PrintNumber

{

public void print(int num1);

}

public class Slip10_1

{

public static void main(String[] a)

{

PrintNumber p = n -> System.out.println("Cube is: "+ n*n*n);

p.print(5);

}

}

Q2) Write a program to create a package name student. Define class StudentInfo with method to display information about student such as rollno, class, and percentage. Create another class StudentPer with method to find percentage of the student. Accept student details like rollno, name, class and marks of 6 subject from user. [20 marks]

//StudentInfo.java

package student;

public class StudentInfo

{

public void display_student(int r,String n, String c,double p)

 { 

   System.out.println ("Roll No. = "+r);

   System.out.println ("Name = "+n);

   System.out.println ("Class = "+c);

   System.out.println ("Percentage = "+p+"%");

 }

}

//StudentPer.java

package student;

public class StudentPer

{

public double calcper(int[] mar)

{

double per;

int sum=0;

for(int i=0;i<6;i++)

sum+=mar[i];

per=(double)sum/6;

return per;

}

}

//main program

import java.util.Scanner;

import student.*;

class StudentData

{

public int roll,m[];

public String name,cname;

public double per;

public StudentData(int r,String n,String c,int m[])

{

roll=r;

name=n;

cname=c;

this.m=m;

}

}

class Slip10_2

{

public static void main(String[] args) 

{

int m[]=new int[6];

Scanner sc=new Scanner(System.in);

System.out.println ("Enter Roll No.");

int roll=sc.nextInt();

System.out.println ("Enter Name");

String name=sc.next();

System.out.println ("Enter class");

String c=sc.next();

System.out.println ("Enter marks of 6 subjects");

for(int i=0;i<6;i++)

m[i]=sc.nextInt();

StudentData sd=new StudentData(roll,name,c,m);

StudentPer sp=new StudentPer();

sd.per=sp.calcper(m);

StudentInfo si=new StudentInfo();

si.display_student(sd.roll,sd.name,sd.cname,sd.per);

}


Comments

Popular posts from this blog

Slip1

Slip3

Slip2