forked from KottaNiranjan/Resistor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresistor.java
More file actions
39 lines (39 loc) · 812 Bytes
/
Copy pathresistor.java
File metadata and controls
39 lines (39 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.*;
class Resistor{
double resistance;
Resistor(){
resistance=20;
}
Resistor(double r){
resistance =r;
}
void giveData(double r){
resistance=r;
}
}
class SeriesResistor extends Resistor
{
Resistor calculateSeries(Resistor r1[]){
Resistor r=new Resistor();
r.resistance=0;
for(int i=0;i<r1.length;i++){
r.resistance=r.resistance+r1[i].resistance;
}
return r;
}
}
class Execute{
public static void main(String args[]){
Resistor[] rarray = new Resistor[5];
Scanner sc=new Scanner(System.in);
for(int i=0;i<5;i++){
Resistor r=new Resistor();
System.out.println("Enter the resistances:");
r.resistance=sc.nextDouble();
rarray[i] = r;
}
SeriesResistor s=new SeriesResistor ();
Resistor newR = s.calculateSeries(rarray);
System.out.println(newR.resistance);
}
}