3 /** 4 * @Encapsulation testing java OOP - LAB2 5 * @author Amila 6 */ 7 public class Encaps { 8 /** 9 * @param args the command line arguments 10 */ 11 public static void main(String[] args) { 12 Student nalaka = new Student(); 13 setStudent(nalaka,"Nalaka",35,67,true); 14 DisplayStudent(nalaka); 15 16 Student janith = new Student(); 17 setStudent(janith,"Janith",38,58,true); 18 DisplayStudent(janith); 19 } 20 21 private static void setStudent(Student s,String name,int age,int marks,boolean isMale){ 22 s.setName(name); 23 s.setAge(age); 24 s.setMarks(marks); 25 s.setisMail(isMale); 26 } 27 private static void DisplayStudent(Student s){ 28 String sex; 29 if (s.getisMail()) 30 sex="Male"; 31 else 32 sex="Female"; 33 34 System.out.println("\n=================================="+ 35 "\nStudent Name: "+ s.getName() + 36 "\nStudent Age: "+s.getAge()+ 37 "\nStudent Marks: "+s.getMarks()+ 38 "\nStudent Sex: "+sex+ 39 "\n=================================="); 40 } 41 } 42 class Student{ 43 44 private static int count=0; 45 private String Name; 46 private int Age; 47 private int Marks; 48 private boolean isMale; 49 50 public Student(){ 51 this.count++; 52 System.out.println("\nStudent count is "+ this.count); 53 } 54 public void setName(String name){ 55 this.Name=name; 56 } 57 public String getName(){ 58 return this.Name; 59 } 60 public void setAge(int age){ 61 this.Age=age; 62 } 63 public int getAge(){ 64 return this.Age; 65 } 66 public void setMarks(int marks){ 67 this.Marks=marks; 68 } 69 public int getMarks(){ 70 return this.Marks; 71 } 72 public void setisMail(boolean Mail){ 73 this.isMale=Mail; 74 } 75 public boolean getisMail(){ 76 return this.isMale; 77 }
Showing posts with label Labs. Show all posts
Showing posts with label Labs. Show all posts
<html> <header><title>Marks Calculator</title> <style> .txt{ padding:5px; font-size:18px; -moz-border-radius: 10px; border-radius: 10px; border:solid 2px #D7DFEA; } </style> </header> <body> <form name="myForm" method="get"> <div style="padding:50px;"> <h2>Marks Calculator</h2> <div width="50%" style="float: left;padding:50px;background-color:#EEEEEE;height: 100%;"> LAB1:<br> <input type="text" name="lab1" class="txt" value="0" maxlength="20" required>100% <br> LAB2:<br> <input type="text" name="lab2" class="txt" value="0" maxlength="20" required>100% <br> LAB3:<br> <input type="text" name="lab3" class="txt" value="0" maxlength="20" required>100% <br> TMA1:<br> <input type="text" name="tma1" class="txt" value="0" maxlength="20" required>100% <br> OQ1:<br> <input type="text" name="oq1" class="txt" value="0" maxlength="20" required>100% <br> MP1:<br> <input type="text" name="mp1" class="txt" value="0" maxlength="20" required>100% <br> <br> </div> <div width="50%" style="float: left;padding:50px;background-color:#EEEEEE;height: 100%;"> CA:<br/><div id="ca_print" onclick="calculate_ca()" title="Click to calculate CA" style="background-color:#FF9900;width:150px;font-size:20px;padding:5px;color:#fff;cursor: pointer;" align="center">Click here to Calculate CA</div><br/> <div id="eligiblility" style="background-color:#FF9900;width:150px;font-size:20px;padding:5px;color:#fff;" align="center">eligiblility</div> <br><br> FE:<br> <input type="text" id="febox" class="txt" disabled>100% <br/><br/> <div id="finalz" onclick="final_z()" title="Click to calculate Z" style="background-color:#FF9900;width:150px;font-size:20px;padding:5px;color:#fff;cursor: pointer;" align="center">Click here to Calculate Final Z</div> <br><br> </div> </div> </form> </body> <script type="text/javascript"> document.getElementById("febox").disabled = true; function calculate_ca() { //Make variables var lab1 = parseInt(document.forms["myForm"]["lab1"].value); var lab2 = parseInt(document.forms["myForm"]["lab2"].value); var lab3 = parseInt(document.forms["myForm"]["lab2"].value); var tma1 = parseInt(document.forms["myForm"]["tma1"].value); var oq1 = parseInt(document.forms["myForm"]["oq1"].value); var mp1 = parseInt(document.forms["myForm"]["mp1"].value); //start validate 0-100 marks if (0>=lab1 || lab1>=100){ alert("Error! :Lab1 should be in between 0-100"); return false; } if (0>=lab2 || lab2>=100){ alert("Error! :Lab2 should be in between 0-100"); return false; } if (0>=lab3 || lab3>=100){ alert("Error! :Lab3 should be in between 0-100"); return false; } if (0>=tma1 || tma1>=100){ alert("Error! :TMA1 should be in between 0-100"); return false; } if (0>=oq1 || oq1>=100){ alert("Error! :OQ1 should be in between 0-100"); return false; } if (0>=mp1 || mp1>=100){ alert("Error! :MP1 should be in between 0-100"); return false; } //End Validate var slab; var sblab; //make slab.sblab if (lab1 > lab2) slab = lab1; else slab = lab2; if (lab2 > lab3) sblab = lab2; else sblab = lab3; //CA Marks = (OQ*0.1 + TMA*0.2 + Avg(BLAB+SBLAB)*0.3 + MP*0.4) *100 % var ca = (oq1*0.1 + tma1*0.2 + ((slab+sblab)/3)*0.3 + mp1*0.4); //Round Integer print document.getElementById("ca_print").innerHTML = Math.round(ca); //Eligibility criteria is : {OQ*0.1 + TMA*0.2 + Avg(BLAB+SBLAB)*0.3 + MP*0.4} >= 0.4 And MP>=0.4 if (ca >= 40 && mp1 >= 40) { document.getElementById("eligiblility").innerHTML = "Pass"; document.getElementById("eligiblility").style.backgroundColor = '#12BA5C'; document.getElementById("febox").disabled = false; }else { document.getElementById("eligiblility").innerHTML = "Fail"; document.getElementById("eligiblility").style.backgroundColor = '#CD0100'; } } function final_z(){ var lab1 = parseInt(document.forms["myForm"]["lab1"].value); var lab2 = parseInt(document.forms["myForm"]["lab2"].value); var lab3 = parseInt(document.forms["myForm"]["lab2"].value); var tma1 = parseInt(document.forms["myForm"]["tma1"].value); var oq1 = parseInt(document.forms["myForm"]["oq1"].value); var mp1 = parseInt(document.forms["myForm"]["mp1"].value); var ca = (oq1*0.1 + tma1*0.2 + ((lab1+lab2+lab3)/3)*0.3 + mp1*0.4); var fe = parseInt(document.getElementById("febox").value); var z=0; if (fe > 40) z = (ca * 0.5) + (fe * 0.5); else z = fe; var result=0; if (z >= 85){ result = "A+"; }else if (75<= z && z <85){ result = "A"; }else if (70<= z && z <75){ result = "A-"; }else if (63<= z && z <70){ result = "B+"; }else if (55<= z && z<63){ result = "B"; }else if (50<= z && z<55){ result = "B-"; }else if (45<= z && z<50){ result = "C+"; }else if (40<= z && z<45){ result = "C"; }else if (35<= z && z<40){ result = "C-"; }else if (30<= z && z<35){ result = "D+"; }else if (20<= z && z<30){ result = "D-"; }else if (20 > z){ result = "E"; }else{ result = "F"; } document.getElementById("finalz").innerHTML = result; } </script> </html>
Marks Calculator
<!DOCTYPE html>
<html>
<header>
<title>Amila – Personal Web Site”.</title>
<link rel="stylesheet" type="text/css" href="style1.css">
<style>
</style>
</header>
<body style="background-image: url('back.png');background-repeat: repeat;">
<div id="container">
<div id="header">
<h1>
Favourite Artists
</h1>
</div>
<div id="navigation">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="mybooks.html">Books Gallery1</a></li>
<li><a href="myartists.html">Artists Gallery1</a></li>
<li><a href="friendrequest.html">Freind Request</a></li>
</ul>
</div>
<div id="content1">
<h1 class="h4">
Favourite Artists
</h1>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000358/" target="_blank"><img src="images/Daniel Michael.jpg" alt="My Photo" align="left" width="100%">
</a><div class="imgtitle">Daniel Michael</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000093/" target="_blank"><img src="images/Brad Pitt.jpg" alt="My Photo" align="left" width="100%">
</a><div class="imgtitle">Brad Pitt</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000243/" target="_blank"><img src="images/Denzel Washington.jpg" alt="My Photo" align="left" width="100%"></a>
<div class="imgtitle">Denzel Washington</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000154/" target="_blank"><img src="images/Mel Gibson.jpg" alt="My Photo" align="left" width="100%">
</a><div class="imgtitle">Mel Gibson</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000138/" target="_blank"><img src="images/Leonardo DiCaprio.jpg" alt="My Photo" align="left" width="100%"></a>
<div class="imgtitle">Leonardo DiCaprio</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000168/" target="_blank"><img src="images/Samuel L. Jackson.jpg" alt="My Photo" align="left" width="100%"></a>
<div class="imgtitle">Samuel L. Jackson</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000115/" target="_blank"><img src="images/Nicolas Cage.jpg" alt="My Photo" align="left" width="100%">
</a><div class="imgtitle">Nicolas Cage</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000151/" target="_blank"><img src="images/Morgan Freeman.jpg" alt="My Photo" align="left" width="100%">
</a><div class="imgtitle">Morgan Freeman</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000246/" target="_blank"><img src="images/Bruce Willis.jpg" alt="My Photo" align="left" width="100%">
</a><div class="imgtitle">Bruce Willis</div>
</div>
<div class="imgbox1">
<a href="http://www.imdb.com/name/nm0000129/" target="_blank"><img src="images/Tom Cruise.jpg" alt="My Photo" align="left" width="100%">
</a><div class="imgtitle">Tom Cruise</div>
</div>
</div>
<!-- <p>My favourite sport star is jayasuriya-cricketer</p> -->
<div id="footer">
Copyright © AM Hewagama, 2015
<br/>
Contact: amila@lankaship.lk
</div>
</div>
</body>
</html>
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
printf("LAB1 SESSIONS \n\n");
int sample;
int exit=0;
while (sample!=0){
printf("main menu.. \n");
printf("1: WELCOME MESSAGE \n");
printf("2: COMPARE TWO NUMBERS \n");
printf("3: CHECK GRADE IS PASS/FAIL \n");
printf("4: AVERAGE OF 10 NUMBERS \n");
printf("5: DISPLAY SOLID SQUIRE OF *S \n");
scanf("%d",&sample);
printf("YOU ARE RUNNING SAMPLE %d \n\n",sample);
switch (sample){
case 1:
sample1();
break;
case 2:
sample2();
break;
case 3:
sample3();
break;
case 4:
sample4();
break;
case 5:
sample5();
break;
}
printf("\n\nDO YOU WANT TO EXIT? (YES=1,NO=0)");
scanf("%d",&exit);
if (exit==1)
return 0;
} //end while
return 0;
}
int sample1(){
printf("Welcome to C!\n");
return 0;
}
int sample2(){
int num1,num2;
printf("enter two intergers and I will tell you \n the relationships they satisfy:");
scanf("%d%d",&num1,&num2);
printf("\n\n");
printf("TWO NUMBERS ARE: [%d] ,[%d]",num1,num2);
printf("\n\n");
if (num1 == num2){
printf("%d is equel to %d\n",num1,num2);
printf("\n\n");
}
if (num1 != num2){
printf("%d is not equel to %d\n",num1,num2);
printf("\n\n");
}
if (num1 < num2){
printf("%d is less than %d\n",num1,num2);
printf("\n\n");
}
if (num1 > num2){
printf("%d is grater than %d\n",num1,num2);
printf("\n\n");
}
if (num1 <= num2){
printf("%d is less than or equel %d\n",num1,num2);
printf("\n\n");
}
if (num1 >= num2){
printf("%d is grater than or equel %d\n",num1,num2);
printf("\n\n");
}
return 0;
}
int sample3(){
int grade;
printf("PLEASE ENTER THE GRADE:");
scanf("%d",&grade);
if (grade > 70)
printf("Pass\n");
else
printf("Fail\n");
return 0;
}
int sample4(){
int counter,grade,total,average;
total=0;
counter=1;
while (counter<=10){
printf("enter grade:");
scanf("%d",&grade);
total=total+grade;
counter=counter+1;
}
//end while
average = total /10;
printf("Class average is %d\n",average);
return 0;
}
int sample5(){
int x,y;
for(x=1;x<6;x++){
for(y=5;y>0;y--){
printf("*");
}
printf("\n");
}
return 0;
}