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

OOP Lab 2

This document contains the source code for 4 Java programming tasks. Task 1 requests user input for year, number of courses, and GPA and displays it. Task 2 splits a 5 digit number into digits. Task 3 calculates a mathematical expression based on a user-input x value. Task 4 calculates displacement given initial position, time, initial velocity, and acceleration.

Uploaded by

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

OOP Lab 2

This document contains the source code for 4 Java programming tasks. Task 1 requests user input for year, number of courses, and GPA and displays it. Task 2 splits a 5 digit number into digits. Task 3 calculates a mathematical expression based on a user-input x value. Task 4 calculates displacement given initial position, time, initial velocity, and acceleration.

Uploaded by

Mohammad Anas
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

OOP

Lab-2
Task-1:
Source code:
package taskone;

/**

* @author manas.bese19seecs

*/

import java.util.Scanner;

public class TaskOne {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("Enter your year: ");

String year = input.next();

System.out.println("Enter the number of courses you are taking: ");

int courses = input.nextInt();

System.out.println("Enter your GPA: ");


float gpa = input.nextFloat();

System.out.println("Year: "+year+"\nNumber of Courses: "+courses+"\nGPA: "+gpa);Fresh

// TODO code application logic here

Snapshots:

Task-2:
Source Code:
package tasktwo;

/**

* @author manas.bese19seecs

*/

import java.util.Scanner

import java.lang.Math
public class TaskTwo {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

// initialize variables

int num;

System.out.print("Enter a number with five digits: ");

num = input.nextInt(); // read five digits input

// ensure input number with five digits

if ( (num >= 10000) && (num <= 99999) )

System.out.printf("%d ", (num / 10000));

System.out.printf("%d ", (num / 1000)%10);

System.out.printf("%d ", (num / 100) % 10);

System.out.printf("%d ", (num % 100) / 10);

System.out.printf("%d ", (num % 10));

// if entered number more than five digits

if (num > 99999)

System.out.println("You had entered a number more than five digits.");

// if entered number less than five digits


if (num <= 9999)

System.out.println("You had entered a number less than five digits.");

Snapshots:

Task-3:
Source Code:
package taskthree;

/**

* @author manas.bese19seecs

*/

import java.util.Scanner;

import java.lang.Math;

public class TaskThree {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {


Scanner input = new Scanner(System.in);

System.out.println("Enter the value of x: ");

int x = input.nextInt();

double y = x * (x * (x * (12.3 * x - 9.1) + 19.3) - 4.6) + 34.2;

System.out.println(y);

Task-4:
Source Code:
package taskfour;

/**

* @author manas.bese19seecs

*/

import java.util.Scanner;

public class TaskFour {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner input = new Scanner(System.in);


System.out.println("Enter the value of s0");

float s0 = input.nextFloat();

System.out.println("Enter the value of t");

float t = input.nextFloat();

System.out.println("Enter the value of Initial Velocity");

float v0 = input.nextFloat();

System.out.println("Enter the value of acceleration: ");

float a = input.nextFloat();

double s = s0 + (v0 * t) + (0.5 * a * (t**2));

System.out.println(s);

// TODO code application logic here

You might also like