Upload files to "OOP/Java/Lab/Week10"
This commit is contained in:
parent
22f306573d
commit
0b8cfc509f
46
OOP/Java/Lab/Week10/Sum.java
Normal file
46
OOP/Java/Lab/Week10/Sum.java
Normal file
@ -0,0 +1,46 @@
|
||||
import java.util.*;
|
||||
class floatnum extends Exception
|
||||
{
|
||||
float input;
|
||||
floatnum(float num)
|
||||
{
|
||||
input=num;
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
return "Error:"+input+" is a Floating point number";
|
||||
}
|
||||
}
|
||||
class Input_Exception
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
int n,sum=0;
|
||||
float input=0;
|
||||
Scanner in=new Scanner(System.in);
|
||||
System.out.println("Enter the numbers one at a time,enter -1 to calculate the sum");
|
||||
while(true)
|
||||
{
|
||||
try
|
||||
{
|
||||
input=in.nextFloat();
|
||||
if(input == -1)
|
||||
{
|
||||
System.out.println("Sum="+sum);
|
||||
break;
|
||||
}
|
||||
else if(input%1!=0)
|
||||
{
|
||||
throw new floatnum(input);
|
||||
}
|
||||
else
|
||||
{
|
||||
sum=sum+(int)(input);
|
||||
}
|
||||
}
|
||||
catch(floatnum e)
|
||||
{
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
OOP/Java/Lab/Week10/Valid_matrix.java
Normal file
29
OOP/Java/Lab/Week10/Valid_matrix.java
Normal file
@ -0,0 +1,29 @@
|
||||
import java.util.*;
|
||||
class InvalidMatrixException extends Exception
|
||||
{
|
||||
public String toString()
|
||||
{
|
||||
return "InvalidMatrixException:this is an Invalid Matrix";
|
||||
}
|
||||
}
|
||||
public class Valid_matrix {
|
||||
public static void main(String[] args) {
|
||||
int row,col;
|
||||
Scanner in=new Scanner(System.in);
|
||||
System.out.println("Enter the number of rows and columns");
|
||||
row=in.nextInt();
|
||||
col=in.nextInt();
|
||||
try
|
||||
{
|
||||
if(row!=col)
|
||||
{
|
||||
throw new InvalidMatrixException();
|
||||
}
|
||||
System.out.println("This is a valid matrix");
|
||||
}
|
||||
catch(InvalidMatrixException e)
|
||||
{
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
17
OOP/Java/Lab/Week10/numberformatexception.java
Normal file
17
OOP/Java/Lab/Week10/numberformatexception.java
Normal file
@ -0,0 +1,17 @@
|
||||
import java.util.*;
|
||||
public class numberformatexception {
|
||||
public static void main(String[] args) {
|
||||
int a;
|
||||
Scanner in=new Scanner(System.in);
|
||||
System.out.print("Input:");
|
||||
try{
|
||||
a=Integer.parseInt(in.nextLine());
|
||||
System.out.println("Number entered is "+a);
|
||||
}
|
||||
catch(NumberFormatException e)//As NumberFormatException is typecasting error
|
||||
{
|
||||
System.out.println("Error:"+e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
OOP/Java/Lab/Week10/root.java
Normal file
23
OOP/Java/Lab/Week10/root.java
Normal file
@ -0,0 +1,23 @@
|
||||
import java.util.*;
|
||||
public class root {
|
||||
public static void main(String[] args) {
|
||||
Scanner in=new Scanner(System.in);
|
||||
System.out.println("Enter the number");
|
||||
double num=in.nextDouble();
|
||||
try
|
||||
{
|
||||
if(num<0)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
System.out.print("Sqaure root=");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
System.out.print("Negative number was entered\nsqaure root=i");
|
||||
num=-num;
|
||||
}
|
||||
double root=Math.sqrt(num);
|
||||
System.out.print(root);
|
||||
}
|
||||
}
|
47
OOP/Java/Lab/Week10/student.java
Normal file
47
OOP/Java/Lab/Week10/student.java
Normal file
@ -0,0 +1,47 @@
|
||||
import java.util.*;
|
||||
class studrecord{
|
||||
String Name;
|
||||
int rollno;
|
||||
int marks[]=new int[3];
|
||||
int percent=0;
|
||||
studrecord(String name,int roll, int marks[])
|
||||
{
|
||||
Name=name;
|
||||
rollno=roll;
|
||||
this.marks=marks;
|
||||
percent=(marks[0]+marks[1]+marks[2])/3;
|
||||
}
|
||||
char getgrade()
|
||||
{
|
||||
if(percent>90)
|
||||
return 'A';
|
||||
else if(percent>80)
|
||||
return 'B';
|
||||
else if(percent>70)
|
||||
return 'C';
|
||||
return 'F';
|
||||
}
|
||||
}
|
||||
public class student {
|
||||
public static void main(String[] args) {
|
||||
Scanner in=new Scanner(System.in);
|
||||
try{
|
||||
System.out.println("Enter the name,roll number and the marks in 3 subjects simutaneously");
|
||||
String name=in.nextLine();
|
||||
int roll=Integer.parseInt(in.nextLine());
|
||||
int marks[]=new int[3];
|
||||
for(int i=0;i<3;i++)
|
||||
{
|
||||
int a=Integer.parseInt(in.nextLine());
|
||||
marks[i]=a;
|
||||
}
|
||||
studrecord stud=new studrecord(name, roll, marks);
|
||||
System.out.println("Succesfully Entered");
|
||||
System.out.println("Percentage="+stud.percent+"%\nGrade:"+stud.getgrade());
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
System.out.println("Error:NumberFormatException Occured");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user