OOPS

Today we gonna create small project to calculate hsc marks.

package Oops;

import java.util.Scanner;

public class Hscmarkcalculator {

int noofsubject; int marks; int total;

public static void main(String[] args) {

// TODO Auto-generated method stub

Hscmarkcalculator hsc=new Hscmarkcalculator();

hsc.getmark();//method calling statement

hsc.Calculategrade();// method calling statement

}

private void Calculategrade() {//method Body

// TODO Auto-generated method stub

if(total>1000)

{

System.out.println(“A Grade”);

}

else if(total > 800)

{

System.out.println(“B Grade “);

}

else

{

System.out.println(“C Grade”);

}

}

private int getmark() {//method body

// TODO Auto-generated method stub

System.out.println(“Please enter number of subjects”);

Scanner scannerObj = new Scanner(System.in);

int len = scannerObj.nextInt();

int[] marks = new int[len];

total = 0;

for (int sub = 0; sub < len; sub++) {

System.out.println(“Please enter marks”);

marks[sub] = scannerObj.nextInt();

System.out.println(“You entered ” + marks[sub]);

total = total + marks[sub];

}

System.out.println(“Your total mark is ” + total);

return total;

}

}

result

Please enter number of subjects

6

Please enter marks

180

You entered 180

Please enter marks

190

You entered 190

Please enter marks

150

You entered 150

Please enter marks

160

You entered 160

Please enter marks

170

You entered 170

Please enter marks

178

You entered 178

Your total mark is 1028

A Grade

In the above program we create method calling and method body. Here we use the return type, that repeat the value where the method was calling.

Note:after return keyword line, below lines are not execueted.

Method calling

hsc.getmark();//method calling statement

hsc.Calculategrade();// method calling statement

Method body

private int getmark()

{

}

private void Calculategrade()

{

}

Object:

object is nothing but, combination of state and behaviour. And its a representative of class. The example of object

ex:man

state:tall,short, black skin,white skin, etc,.

behaviour:walk,run,jump etc,.

Class:

it gives an template or blueprint.and the class of no.of objects and methods.

It is a non primitive data type.

Method:

it is a Behaviour

Set of instructions with a name

Code Reusability

Member function

Smallest logical unit

void:

if we use void in method signature like

public static void main(String[] args)

it means nothing return.

Return:

if we use return we send the value where it was called.

Ex:

hsc.getmark()//method calling

private int getmark()// return type mention datatype

return // return the value

Leave a comment

Design a site like this with WordPress.com
Get started