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