Tutorialspoint

Case study 2

import java.util.*;
public class Course {
   private String name;
 private  String  code;
   private String instructure_name;

 ArrayList <String> students = new ArrayList <String>();

   public Course(String N, String  C, String IN) {// constructure
      name=N;
      code=C;
      instructure_name=IN;
      
      
   }

public Course(String N, String  C) {// 1- constructure without instructrue name
      name=N;
      code=C;
      instructure_name="";
      
      
   }
  public void setname(String N) {
       name=N;
   }
 public void setcode(String C) {
      code=C;
   }
   
  public void setinstructure(String i) {
       instructure_name=i;
   }
   
   public void Add_student(String s){ // function to add student to course
       students.add(s);
   }
   public void Remove_student(String s){
       for (int i=0;i<students.size();i++)
       if (s==students.get(i)){ // find the given student name in the list of student enrolled in the course
       System.out.println("Student name "+students.get(i)+ " dropped the course");
       students.remove(i);// remove the student
       
       
       }
   }
   
   public void check_enrolled(String s){
       boolean enroll=false;
       for (int i=0;i<students.size();i++){
           if (s==students.get(i)){
            enroll=true;
               break;
           }
           
       }
       if (enroll==true)
       System.out.println("Student name "+s+ " enrolled in the course");
       else
        System.out.println("Student name "+s+ " did not enroll in the course");
   }
   public String getname(){
       return name;
   }
   
   public String getcode(){
       return code;
   }
   
   public String getinstructure(){
       return instructure_name;
   }
   
   public void print_courseinfo(){
       if (code.charAt(0)=='I'&& code.charAt(1)=='T'){
       System.out.println("This is an IT course");}
       else {
        System.out.println("This is not an IT course");
       }
       
   }
   


public static void main(String[] args) {
  Course C1 = new Course("java","IT101","Khalid"); // create c1 object of course class
  
  Course C2 = new Course("operating system","CS102","Ahmed"); // create c1 object of course class
  
  C1.print_courseinfo();
  C2.print_courseinfo();
  
  C1.setname("OS");
  System.out.println(C1.getname());
  
   Course C3=new Course("Data base","IT103"); // test case1
   C3.setinstructure("Ahmed");
    System.out.println("The istructre of "+C3.getname()+" course is Dr."+C3.getinstructure());
    //test case 2
    C3.Add_student("Saad");
    C3.Add_student("Hossam");
    C3.Add_student("Saleh");
    
    //test case 3
    C3.check_enrolled("Saad"); // enrolled
    C3.check_enrolled("Mohammed");// not enroll
    
    //test case 4
    C3.Remove_student("Saleh");
    C3.check_enrolled("Saleh");
   
  }
}

Compile and Execute Java8 Online

public class HelloWorld{

     public static void main(String []args){
        int N=-4;
        int L=0;
        int R=1;
        
        while(true){
            L=operationl(L,R);
        //System.out.println(L);
         while(L != N || R != N){
        L=operationl(L,R);
        break;
         }

         if(L == N ||R==N){
            System.out.println(L);
            break;
        }else if(L != N && R != N){
            System.out.println("fail");
            break;

        }
       
        }
        
        
                

        
        
     
        
    
    
        
        
        
        
        
     }
       public static int operationl(int n,int k){
          int l=n,r=k;
        int res;
          res= 2*l-r;
          
          return res;
      }  
      
      public static int operationr(int k,int n){
          int l=k,r=n;
        int res;
          res= 2*r-l;
          
          return res;
      }  
}

Angular v1.3.3 Practive

<!doctype html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
    <script>
        var app = angular.module("myApp", []);
        app.controller("myCtrl", function($scope) {
            $scope.records = [
                "Alfreds Futterkiste",
                "Berglunds snabbköp",
                "Centro comercial Moctezuma",
                "Ernst Handel"
            ]
            
            $scope.values = [
                {
                    myvalue: 1,
                    mytext: "hello",
                    myjob: "UI"
                },
                {
                    myvalue: 2,
                    mytext: "hello friend",
                    myjob: "UI Dev"
                }
            ]
        })
    </script>
  </head>
  <body ng-app="myApp" ng-controller="myCtrl">
    <div>
      <label>Name:</label>
      <h1 ng-repeat="x in records">{{x}}</h1>
      <p ng-repeat="y in values">{{y.mytext}}</p>
      <input type="text" ng-model="yourName" placeholder="Enter a name here">
      <hr>
      <h1>Hello {{yourName}}!</h1>
    </div>
  </body>
</html>

Pyramid

c

/*C program to print following Pyramid:
        *
       * *
      * * *
     * * * *
    * * * * *
*/

#include<stdio.h>

#define MAX	5

int main()
{
    int i,j;
    int space=4;
    /*run loop (parent loop) till number of rows*/
    for(i=0;i< MAX;i++)
    {
	    /*loop for initially space, before star printing*/
	    for(j=0;j< space;j++)
	    {
		    printf(" ");
	    }
	    for(j=0;j<=i;j++)
	    {
		    printf("* ");
	    }
		
	    printf("\n");
	    space--;	/* decrement one space after one row*/
    }
    return 0;
}

Bitch

let rec invList = function
    |[] -> []
    |t::q-> (invList q)@[t]

wqwe

import java.io.File;
import java.io.FileReader;

public class FilenotFound_Demo {

   public static void main(String args[]) {		
      File file = new File("E://file.txt");
      FileReader fr = new FileReader(file); 
   }
}

ShellOne

# To print the City been entered

echo "Enter the City name"
read CITY
echo "City name entered is $CITY"

# To print the date been entered

read date
echo "Date entered is $date"

# To print the name assigned and check its nature

name="SHABIR JAMEEL"
echo "Name of the person is $name"

#To print age been assigned
age='32'
echo "Age of the person is $age"

unset age
echo "Value in the variable age is $age"

echo "PID of the sessio is $$"
echo "Filename of the script is $0"
echo "Exit status of last statement is $?"


arr_new=('DELHI', 'MUMBAI', 'HYDERABAD', 'CHENNAI')
echo ${arr_new[0]}
echo ${arr_new[1]}
echo ${arr_new[2]}
echo ${arr_new[3]}

echo ${arr_new[*]}

a=5
echo "Value of a is $a"
b=15
echo "Value of b is $b"

vals=`expr $a + $b`
echo "Sum of a and b is $vals"

vald=`expr $a - $b`
echo "Difference of a and b is $vald"

valm=`expr $a * $b`
echo "Multiplication of a and b is $valm"

vali=`expr $a / $b`
echo "Division of a and b is $vali"

vale=`expr $a % $b`
echo "Modulus of a and b is $vale"

if [ $a -eq $b ]
then
echo "Values of a and b are equal"
else
echo "Values of a and b are NOT equal"
fi

if [ $a -lt $b ]
then
echo "Value of a is less than b"
else
echo "Value of b is less than a"
fi

if [ $a -gt $b ]
then
echo "Value of a is greater than b"
else
echo "Value of b is greater than a"
fi

a=0
while [ "$a" -lt 10 ]    # this is loop1
do
   b="$a"
   while [ "$b" -ge 0 ]  # this is loop2
   do
      echo -n "$b "
      b=`expr $b - 1`
   done
   echo
   a=`expr $a + 1`
done

str="LIRIL"
echo "Value of str is $str"

len=${#str}
echo "Length of the String $len"

for((i = $len - 1; i>=0; i--))
do
 rev="$rev${str:$i:1}"
done
echo "$rev"

echo $a
echo "Value of a is $a \n"
echo -e "Value of a is $a \n"

USERS=`who | wc -l`
echo "Logged in user are $USERS"

echo $

DATE=`date`
echo "Current Date is $DATE"

#cat a

echo `\n`

cat << EOF
This is a simple lookup program 
for good (and bad) restaurants
in Cape Town.
EOF

Hello() {
    echo "This is a function in Shell"
}

Hello

Hellonew() {
    echo "Parameters $a $b"
}

Hellonew

Hellotest() {
    echo "New Function"
    return 10
}

Hellotest

ret=$?

echo "Return value is $ret"

Functionone() {
    echo "This is the statement from first function"
    Functiontwo
}
Functiontwo(){
    echo "This is the statement from second function"
}

Functionone

/bin
/etc
/lib

touch filenew

pwd

ls

ls -l

vi filetwo
i
This is a sample file created

cat filetwo

Java Script Date Display

<!DOCTYPE html>
<html>
   <head>
      <title>Web Page Design</title>
      <script>
         document.writeln(new Date().toISOString().slice(0, 19).replace('T', ' '));

      </script>
   </head>
   <body>
      <br>Current Date is displayed above...
   </body>
</html>

Compile and Execute Java Online

public class HelloWorld{

     public static void main(String []args){
         try
         {
        System.out.println("Hello World");
        System.out.println(1/0);
        System.out.println("Hello World 3");
         }
         catch(Exception e)
         {
         System.out.println("Exception"+e.getMessage());
         }
         System.out.println("Hello World 2");
     }
}

test

#
# Hello World Program in Perl
#
use utf8;
use Encode;

my $subject = 'perl Jügend 遺跡発見 áéíóú 遱葑癱覂';

my $encoded = encode('MIME-Header', $subject);
print $encoded . "\n";

my $encoded_again = encode('MIME-Header', $encoded);
print "\n\n" . $encoded_again . "\n\n";

print "bad" unless ($encoded eq $encoded_again);

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.