0% found this document useful (0 votes)
13 views

Assignment #1: "Object Oriented Program (Oop) "

The document contains 4 Java programs. The first program takes a name and age as input and displays it. The second program takes 2 values as input, performs some calculations, and displays the result. The third program takes a surname, CGPA, and semester as input and displays it. The programs demonstrate basic input/output and object-oriented programming concepts.

Uploaded by

Slow Gamerz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Assignment #1: "Object Oriented Program (Oop) "

The document contains 4 Java programs. The first program takes a name and age as input and displays it. The second program takes 2 values as input, performs some calculations, and displays the result. The third program takes a surname, CGPA, and semester as input and displays it. The programs demonstrate basic input/output and object-oriented programming concepts.

Uploaded by

Slow Gamerz
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment #1

“OBJECT ORIENTED PROGRAM (OOP)”

NAME: MINHAJ MOHAMMAD SIDDIQUI


ROLL NO: 7462

1.Write a java program taking name and age as input from the user and
displaying it
package student;

import java.util.Scanner;

public class student {


public static void main(String args[]){

String name;
int age;
Scanner input = new Scanner(System.in);
System.out.println("enter name");
name = input.next();
System.out.println("\nenter age");
age = input.nextInt();

System.out.println("\n"+name + " " + age);


}
}

2.Write a java program taking 2 values as input from the user and then taking
the square of 1st value and multiplying it with 2nd value. Store it in the new
variable now multiply the it with 2 and raise the 3rd value with power 3 and
display.

package student;

import java.util.Scanner;

public class student {


public static void main(String args[]){
double a,b,c,ans;

Scanner input = new Scanner(System.in);


System.out.println("enter value of a: ");
a = input.nextDouble();
System.out.println("enter value of b: ");
b = input.nextInt();
c = b* Math.sqrt(a);
ans = 2 * Math.pow(c, 3);
System.out.printf("ans is = %.3f\n", ans);
}
}

3. Write a java program taking surname, cgpa, semester as an input and display
it.
package student;

import java.util.Scanner;

public class student {

String surname;
double gpa,sem;

Scanner input = new Scanner(System.in);

public void getdata(){


System.out.println("enter surname");
surname = input.nextLine();
System.out.println("enter gpa");
gpa = input.nextDouble();
System.out.println("enter sem");
sem = input.nextDouble();
System.out.println("surname: " + name + " gpa: " + gpa + " sem: " + sem +
"\n");
}

public static void main(String args[]){


student yasir = new student();
student nasir = new student();
student javad = new student();
student minhaj = new student();

yasir.getdata();
nasir.getdata();
javad.getdata();
minhaj.getdata();

}
}

You might also like