WEB SERVICE - CALCULATOR
Servlets - Factorial Calculation
FormFact.html
<!-- Servlet,
form data and validation -->
<html>
<head>
<title> Forms, servlet and
factorial</title>
<style>
h3{text-align:center}
</style>
<script
type="text/javascript" language="javascript">
function fnvalidate()
{
// User Name
Validation
var Num =
document.FN.f1.value;
if
(Num.toString().trim().length==0)
{
alert(
"Error...Enter number" );
document.FN.f1.focus()
;
return
false;
}
if( isNaN(Num))
{
alert(
"Invalid Number! Should have only digits." );
document.FN.f1.focus()
;
return
false;
}
return true;
}
</script>
</head>
<body>
<br/><h3> Factorial
Calculator </h3><br/><br/>
<center>
<form name="FN" method="get"
action="http://localhost:8088/WT/FactCalc" onsubmit="return
fnvalidate();">
<label> Enter Number :
</label>
<input
type="text" name="f1" />
<br/><br/>
<input
type="submit" />
<input
type="reset" />
</form>
</html>
FactCalc.java
import
java.io.*;
import
javax.servlet.*;
import
javax.servlet.http.*;
public class
FactCalc extends HttpServlet
{
int N;
public void init(ServletConfig sc)
{
}
public void service(HttpServletRequest
req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter pw =
res.getWriter();
N =
Integer.parseInt(req.getParameter("f1"));
int fact=1;
for(int i=1;i<=N;i++)
fact=fact*i;
pw.println("<html><body><center>");
pw.println("<h3>");
pw.println("Factorial of
"+N +" is "+fact);
pw.println("</h3>");
pw.println("</center></body></html>");
pw.close();
}
public void destroy()
{
}
}
Thread Synchronization in C#
Thread Synchronization in C#
using System;
using System.Collections;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
namespace CSharp
{
public class Q
{
Queue q = new Queue();
public void put(int n)
{
lock (this)
{
while(q.Count==1)
{
Monitor.Wait(this);
}
q.Enqueue(n);
Monitor.Pulse(this);
}
}
public int get()
{
lock (this)
{
while (q.Count==0)
{
Monitor.Wait(this);
}
int n = (int)q.Dequeue();
Monitor.Pulse(this);
return n;
}
}
}
public class Consumer
{
Q q;
public Consumer(Q q)
{
this.q = q;
new Thread(new ThreadStart(this.Consume)).Start();
}
public void Consume()
{
for (int i=1; i <= 5; i++)
{
int n = q.get();
Console.WriteLine ("Consuming {0}", n);
Thread.Sleep(200);
}
}
}
public class Producer
{
Q q;
public Producer(Q q)
{
this.q = q;
new Thread(new ThreadStart(this.Produce)).Start();
}
public void Produce()
{
for (int i=1; i <= 5; i++)
{
q.put(i);
Console.WriteLine ("Producing {0}", i);
Thread.Sleep(200);
}
}
}
public class Program
{
public static void Main(string[] args)
{
Q q = new Q();
new Producer(q);
new Consumer(q);
}
}
}
BEEME 2 Protection devices
BEEME 2 Comparisons
Fuse
|
Circuit breaker
|
Detects and interrupts the fault current
|
Only interrupts the fault current. Detection is done by relay system
|
Automatic operation
|
Not automatic. Relay system is required to operate it
|
Breaking capacity is less
|
Has large breaking capacity
|
Arc interruption is simple
|
Arc interruption is complicated
|
Operating time is small. Operating speed is high
|
Operating time is large. Operating speed is comparatively less
|
Replacement / rewiring required after each operation
|
No replacement needed. Easy to reset
|
Simple design. Cheap
|
Complicated design. expensive
|
Horizontal axis wind turbines
|
Vertical axis wind turbines
| |
Axis of rotation
|
Axis of rotation is parallel to ground and wind steam
|
Axis of rotation is perpendicular to ground and wind stream
|
Mount point
|
Gearbox and generator are mounted above the ground with a tower to support them
|
Gearbox and generator are mounted at ground level. Hence does not require any support tower.
|
Output energy
|
Overall energy output is more
|
Overall energy output is less
|
Efficiency
|
Overall efficiency is more
|
Overall efficiency is less
|
Stress
|
Higher stress is put at the base of the blade by the wind
|
Higher stress is put at the center of the blade by the wind
|
Structural support
|
Requires more structural support
|
Requires less structural support
|
Installation and maintenance
|
Installation and maintenance is hard
|
Installation and maintenance is easy
|
Yaw control
|
Yaw control is necessary to turn rotor so that the blades face the wind
|
Yaw control not needed as rotor reacts to wind from any direction
|