Input name of a student and two marks. Marks are out of 40 for each subject. Find percentage of total and print it
along with name.
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter name and two marks”);
String na=sc.nextLine();
double m1=sc.nextDouble():
double m2=sc.nextDouble():
double percent=(m1+m2)/80.0*100:
System.out.println(“Name: “+na);
System.out.println(“Percentage: “+percent);
}
}
2.1.
Input name and two marks. Marks are out of 40 for each subject. Find percentage of total.
If percentage is 40 or above print "Admission is granted" along with name.
Otherwise nothing to be done.
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter name and two marks”);
String na=sc.nextLine();
double m1=sc.nextDouble():
double m2=sc.nextDouble():
double percent=(m1+m2)/80.0*100:
if(percent>=40)
{
System.out.println(“Name: "+na);
System.out.println(“Admission is granted.");
}
}
}
2.2.
Input two marks of a student. Marks are in 40 each. Find percentage of total.
If percentage is 40 or above print "Admission is granted".
Otherwise print "No Admission."
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter two marks”);
double m1=sc.nextDouble():
double m2=sc.nextDouble():
double percent=(m1+m2)/80.0*100:
if(percent>=40)
System.out.println(“Admission is granted.");
else
System.out.println(“No Admission.");
}
}
2.3.
Input percentage of marks. Print result.
percentage 80 or above : Distinction. 60 or above : First class.
percentage 50 or above : Second class. 40 or above : Third class.
Others : Failed
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter percentage of marks”);
double per=sc.nextDouble():
if(per>=80)
System.out.println(“Distinction.");
else if(per>=60)
System.out.println(“First class.");
else if(per>=50)
System.out.println(“Second class.");
else if(per>=40)
System.out.println(“Third class.");
else
System.out.println(“Failed.");
}
}
2.4.
Input percentage of marks and syllabus. Print result. ExcellentGoodSatisfactory
ICSE (I)Mark: >=75Mark: >=50 Below 50
CBSE (C) Mark: >=80Mark: >=60 Below 60
Others Wrong choice
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter mark and syllabus [I/C]”);
double m=sc.nextDouble():
char s=sc.next().charAt(0);
if(s=='I'||s=='i')
{
if(m>=75)
System.out.println(“Excellent”);
else if(m>=50)
System.out.println(“Good”);
else
System.out.println(“Satisfactory”);
}
else if(s=='C'||s=='c')
{
if(m>=80)
System.out.println(“Excellent”);
else if(m>=60)
System.out.println(“Good”);
else
System.out.println(“Satisfactory”);
}
else
System.out.println(“Wrong choice”);
}
}
2.5.
Write a menu driven program: 1) Input average, print "Passed" or "Failed". Pass mark is 40 or above.
2) Input percentage, print "Admission granted" or "No admission". Admission percentage is 80 or above.
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("1 Average: Passed or Failed.");
System.out.println("2 Percentage: Admission or No Admission.");
System.out.println("Enter your choice");
int ch=sc.nextInt();
switch(ch)
{
case 1: System.out.println("Input average of marks: ");
double avg=sc.nextDouble();
if(avg>=40)
System.out.println("Passed");
else
System.out.println("Failed");
break;
case 2: System.out.println("Input percentage of marks: ");
double per=sc.nextDouble();
if(per>=80)
System.out.println("Admission granted");
else
System.out.println("No admission");
break;
default: System.out.println("Wrong input");
}
}
}
3.1.
Input name and percentage of marks of n students. Print "Admission granted" or "No admission" with name.
Admission mark is 80 or above. Also find total number of students who got admission.
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter number of students”);
int n=sc.nextInt();
int c=0;
for(int i=1;i<=n;i++)
{
System.out.println(“Enter name and mark”);
String name=sc.nextLine();
double m=sc.nextDouble();
if(m>=80)
{
System.out.println(“Name: “+name);
System.out.println(“Admission granted“);
c++;
}
else
{
System.out.println(“Name: “+name);
System.out.println(“No admission”);
}
}
System.out.println(“Count of admissions: “+c);
}
}
3.2.
Input name and percentage of marks of some students. Print "Admission granted" or "No admission".
Admission mark is 80 or above. Also find total number of students who got admission.
Program should continue as long as user wishes.
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int c=0;
char ch='Y';
while(ch=='Y'ch=='y')
{
System.out.println(“Enter name and mark”);
String name=sc.next();
double m=sc.nextDouble();
if(m>=80)
{
System.out.println(“Name: “+name);
System.out.println(“Admission granted“);
c++;
}
else
{
System.out.println(“Name: “+name);
System.out.println(“No admission”);
}
System.out.println("Do you want to continue? [Y/N]: ");
ch=sc.next().charAt(0);
}
System.out.println(“Count of admissions: “+c);
}
}
3.3
Input name and percentage of marks of some students. Print "Admission granted" or "No admission".
Admission mark is 80 or above. Also find total number of students who got admission.
Program should continue as long as user wishes.
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int c=0;
char ch;
do
{
System.out.println(“Enter name and mark”);
String name=sc.next();
double m=sc.nextDouble();
if(m>=80)
{
System.out.println(“Name: “+name);
System.out.println(“Admission granted“);
c++;
}
else
{
System.out.println(“Name: “+name);
System.out.println(“No admission”);
}
System.out.println("Do you want to continue? [Y/N]: ");
ch=sc.next().charAt(0);
}
while(ch=='Y'ch=='y');
System.out.println(“Count of admissions: “+c);
}
}
3.4.
Input n students’ name and m subjects marks. Print average mark of each student.
import java.util.*;
public class Result
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("Input number of students and number of subjects: ");
int n=sc.nextInt();
int m=sc.nextInt();
for(int i=1;i<=n;i++)
{
System.out.println("Enter name: ");
String name=sc.nextLine();
double tot=0.0;
for(int j=1;j<=m;j++)
{
System.out.print("Enter mark: ");
double mark=sc.nextDouble();
tot=tot+mark;
}
double avg=tot/m;
System.out.println("Name: "+name);
System.out.println("Average: "+avg);
}
}
}
4.1.
Input name and percentage of marks of n students into two arrays. Print two separate lists.
1) Those who got admission along with mark, 2) Those who do not get admission. Admission mark is 80 or above.
Also print total number of students who got admission.
import java.util.*;
public class Numbers
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter number of students”);
int n=sc.nextInt();
String name[]=new String[n];
double mark[]=new double[n];
int c=0;
for(int i=0;i<n;i++)
{
System.out.println(“Enter name and mark”);
name[i]=sc.next();
mark[i]=sc.nextDouble();
}
System.out.println(“Students who are eligible for admission”);
System.out.println("Name\tMark");
for(int i=0;i<n;i++)
{
if(mark[i]>=80)
{
System.out.println(name[i]+“\t"+mark[i]);
c++;
}
}
System.out.println(“Students who are not eligible for admission”);
System.out.println("Name\tMark");
for(int i=0;i<n;i++)
{
if(mark[i]<80)
{
System.out.println(name[i]+“\t"+mark[i]);
}
}
System.out.println("Total number of students who got admission: "+c);
}
}
4.2.
Input 30 students’ 10 subjects’ marks. Print a list of students who got mark 80 or above.
Output format:
90.0 : 0 0
85.0 : 2 1
93.5 : 3 4
import java.util.*;
public class Marks
{
public static void main()
{
Scanner sc=new Scanner(System.in);
double mark[][]=new double[30][10];
int i,j;
//To input marks
for(i=0;i<30;i++)
{
for(j=0;j<10;j++)
{
System.out.println("Enter mark: ");
mark[i][j]=sc.nextDouble();
}
}
System.out.println("Students who got mark 80 or above: ");
for(i=0;i<30;i++)
{
for(j=0;j<10;j++)
{
if(a[i][j]>=80)
System.out.println(a[i][j]+" : "+i+" "+j);
}
System.out.println();
}
}
}
5.1.
Define a class to overload methods named int analyze():
1. to count the students who got mark 80 or above of the n input marks
2. to count the students who got mark 60 or above and less than 80 of the n input marks
import java.util.*;
public class Numbers
{
static Scanner sc=new Scanner(System.in);
public static int analyze(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
System.out.println(“Enter mark”);
double mark=sc.nextDouble();
if(mark>=80)
c++;
}
return c;
}
public static int analyze(short n)
{
int c=0;
for(int i=1;i<=n;i++)
{
System.out.println(“Enter mark”);
double mark=sc.nextDouble();
if(mark>=60&&mark<80)
c++;
}
return c;
}
public static void main()
{
System.out.println(“Enter number of students”);
int n1=sc.nextInt();
int c1=analyze(n1);
System.out.println(“Count of students who got mark 80 or above: "+c1);
System.out.println(“Enter number of students”);
short n2=sc.nextShort();
int c2=analyze(n2);
System.out.println(“Count of students mark 60 or above and less than 80: "+c2);
}
}
6.1.
Define a class Result with the following descriptions:
Data members/Instance variables: int roll, String name, double mark, String result
Member methods: 1) Result() - parameterized constructor
2) dataEntry() - to input necessary details 3) process() - to find and store result mark 80 or above : Distinction. 60 or above : First class. mark 50 or above : Second class. 40 or above : Third class. Others : Failed
4) print() - to display details along with result
import java.util.*;
public class Result
{
int roll;
String name;
double mark;
String result;
public Result(int a, String b, double c, String d)