CHANDIGARH UNIVERSITY Institute of Distance and Online Learning SLM Development Committee Prof. (Dr.) H.B. Raghvendra Vice- Chancellor, Chandigarh University, Gharuan, Punjab:Chairperson Prof. (Dr.) S.S. Sehgal Registrar Prof. (Dr.) B. Priestly Shan Dean of Academic Affairs Dr. Nitya Prakash Director – IDOL Dr. Gurpreet Singh Associate Director –IDOL Advisors& Members of CIQA –IDOL Prof. (Dr.) Bharat Bhushan, Director – IGNOU Prof. (Dr.) Majulika Srivastava, Director – CIQA, IGNOU Editorial Committee Prof. (Dr) Nilesh Arora Dr. Ashita Chadha University School of Business University Institute of Liberal Arts Dr. Inderpreet Kaur Prof. Manish University Institute of Teacher Training & University Institute of Tourism & Hotel Management Research Dr. Manisha Malhotra Dr. Nitin Pathak University Institute of Computing University School of Business © No part of this publication should be reproduced, stored in a retrieval system, or transmitted in any formor by any means, electronic, mechanical, photocopying, recording and/or otherwise without the prior written permission of the authors and the publisher. SLM SPECIALLY PREPARED FOR CU IDOL STUDENTS
INTERNET PROGRAMMING PRACTICAL Course Code:BCA146 Credit: 1 Course Objectives: To provide a comprehensive introduction to computer graphics techniques, focusing on 3D modelling, image synthesis & rendering. To carry out computer graphics and to evaluate software and hardware for that use. The course is a foundation for a master´s thesis within computer graphics. EXPERIMENT 1-WAP TO DEVELOP WEB PAGE USING BASIC HTML. Solution: <HTML> <HEAD> <TITLE>Your Title Here</TITLE> </HEAD> <BODY BGCOLOR=\"FFFFFF\"> <CENTER><IMG SRC=\"C:\\Users\\Brij Misra\\Pictures\\Logo copy.jpg\" ALIGN=\"BOTTOM\"></CENTER>
<HR> <a href=\"http://google.com\">Link Name</a> is a link to another nifty site <H1>This is a Header</H1> <H2>This is a Medium Header</H2> Send me mail at <a href=\"mailto:support@yourcompany.com\"> support@yourcompany.com</a>. <P> This is a new paragraph! <P><B>This is a new paragraph!</B> <BR><B><I>This is a new sentence without a paragraph break, in bold italics.</I></B>
<HR> </BODY> </HTML> Output:
EXPERIMENT 2-WAP TO CREATE A WEB PAGE USING CASCADING STYLE SHEET. Solution <html> <head> <style> *{ box-sizing: border-box; } body { font-family: Arial; padding: 10px; background: #f1f1f1; } /* Header/Blog Title */ .header {
padding: 30px; text-align: center; background: white; } .header h1 { font-size: 50px; } /* Style the top navigation bar */ .topnav { overflow: hidden; background-color: #333; } /* Style the topnav links */ .topnav a { float: left; display: block; color: #f2f2f2;
text-align: center; padding: 14px 16px; text-decoration: none; } /* Change color on hover */ .topnav a:hover { background-color: #ddd; color: black; } /* Create two unequal columns that floats next to each other */ /* Left column */ .leftcolumn { float: left; width: 75%; } /* Right column */ .rightcolumn {
float: left; width: 25%; background-color: #f1f1f1; padding-left: 20px; } /* Fake image */ .fakeimg { background-color: #aaa; width: 100%; padding: 20px; } /* Add a card effect for articles */ .card { background-color: white; padding: 20px; margin-top: 20px; }
/* Clear floats after the columns */ .row:after { content: \"\"; display: table; clear: both; } /* Footer */ .footer { padding: 20px; text-align: center; background: #ddd; margin-top: 20px; } /* Responsive layout - when the screen is less than 800px wide, make the two columns stack on top of each other instead of next to each other */ @media screen and (max-width: 800px) { .leftcolumn, .rightcolumn { width: 100%;
padding: 0; } } /* Responsive layout - when the screen is less than 400px wide, make the navigation links stack on top of each other instead of next to each other */ @media screen and (max-width: 400px) { .topnav a { float: none; width: 100%; } } </style> </head> <body> <div class=\"header\"> <h1>My Website</h1> <p>Resize the browser window to see the effect.</p> </div>
<div class=\"topnav\"> <a href=\"#\">Link</a> <a href=\"#\">Link</a> <a href=\"#\">Link</a> <a href=\"#\" style=\"float:right\">Link</a> </div> <div class=\"row\"> <div class=\"leftcolumn\"> <div class=\"card\"> <h2>TITLE HEADING</h2> <h5>Title description, Dec 7, 2017</h5> <div class=\"fakeimg\" style=\"height:200px;\">Image</div> <p>Some text..</p> <p>Sunt in culpa qui officiadeseruntmollitanim id estlaborumconsecteturadipiscingelit, sed do eiusmodtemporincididuntutlabore et dolore magna aliqua. Utenim ad minim veniam, quisnostrud exercitation ullamco.</p> </div> <div class=\"card\">
<h2>TITLE HEADING</h2> <h5>Title description, Sep 2, 2017</h5> <div class=\"fakeimg\" style=\"height:200px;\">Image</div> <p>Some text..</p> <p>Sunt in culpa qui officiadeseruntmollitanim id estlaborumconsecteturadipiscingelit, sed do eiusmodtemporincididuntutlabore et dolore magna aliqua. Utenim ad minim veniam, quisnostrud exercitation ullamco.</p> </div> </div> <div class=\"rightcolumn\"> <div class=\"card\"> <h2>About Me</h2> <div class=\"fakeimg\" style=\"height:100px;\">Image</div> <p>Some text about me in culpa qui officiadeseruntmollitanim..</p> </div> <div class=\"card\"> <h3>Popular Post</h3> <div class=\"fakeimg\"><p>Image</p></div> <div class=\"fakeimg\"><p>Image</p></div> <div class=\"fakeimg\"><p>Image</p></div>
</div> <div class=\"card\"> <h3>Follow Me</h3> <p>Some text..</p> </div> </div> </div> <div class=\"footer\"> <h2>Footer</h2> </div> </body> </html> Output My Website Resize the browser window to see the effect. LinkLinkLinkLink TITLE HEADING
Title description, Dec 7, 2017 Image Some text.. Sunt in culpa qui officiadeseruntmollitanim id estlaborumconsecteturadipiscingelit, sed do eiusmodtemporincididuntutlabore et dolore magna aliqua. Utenim ad minim veniam, quisnostrud exercitation ullamco. TITLE HEADING Title description, Sep 2, 201. Image Some text.. Sunt in culpa qui officiadeseruntmollitanim id estlaborumconsecteturadipiscingelit, sed do eiusmodtemporincididuntutlabore et dolore magna aliqua. Utenim ad minim veniam, quisnostrud exercitation ullamco. About Me Image Some text about me in culpa qui officiadeseruntmollitanim.. Popular Post
EXPERIMENT 3-WAP TO DESIGN QUIZ APPLICATION USING JAVA SCRIPT. Solution Create 3 files 1. Index.html 2. Style.css 3. Question.js 1. <!DOCTYPE html> <html> <head lang=\"en\"> <meta charset=\"UTF-8\"> <title>Quiz</title> <link rel=\"stylesheet\" type=\"text/css\"href=\"style.css\"> </head> <body> <div class=\"grid\">
<div id=\"quiz\"> <h1>Quiz in JavaScript Quiz.com</h1> <hr style=\"margin-bottom: 20px\"> <p id=\"question\"></p> <div class=\"buttons\"> <button id=\"btn0\"><span id=\"choice0\"></span></button> <button id=\"btn1\"><span id=\"choice1\"></span></button> <button id=\"btn2\"><span id=\"choice2\"></span></button> <button id=\"btn3\"><span id=\"choice3\"></span></button> </div> <hr style=\"margin-top: 50px\"> <footer> <p id=\"progress\">Question x of y</p> </footer> </div> </div>
<script src=\"question.js\"></script> </body> </html> 2. body { background-color: #413D3D; } .grid { width: 600px; height: 500px; margin: 0 auto; background-color: #fff; padding: 10px 50px 50px50px; border: 2px solid #cbcbcb; }
.grid h1 { font-family: \"sans-serif\"; background-color: #01BBFF; font-size: 60px; text-align: center; color: #ffffff; padding: 2px 0px; } #score{ color: #01BBFF; text-align: center; font-size: 30px; } .grid #question{ font-family: \"monospace\"; font-size: 30px;
color: #01BBFF; } .buttons { margin-top: 30px; } #btn0,#btn1,#btn2,#btn3{ background-color: #01BBFF; width: 250px; font-size: 20px; color: #fff; border: 1px solid #1D3C6A; margin: 10px 40px 10px 0px; padding: 10px 10px; } #btn0:hover,#btn1:hover,#btn2:hover,#btn3:hover{ cursor: pointer; background-color: #01BBFF;
} #btn0:focus,#btn1:focus,#btn2:focus,#btn3:focus{ outline: 0; } #progress{ color: #2b2b2b; font-size: 18px; } 3. function Quiz(questions){ this.score= 0; this.questions= questions; this.questionIndex= 0; } Quiz.prototype.getQuestionIndex=function(){ returnthis.questions[this.questionIndex];
} Quiz.prototype.guess=function(answer){ if(this.getQuestionIndex().isCorrectAnswer(answer)){ this.score++; } this.questionIndex++; } Quiz.prototype.isEnded=function(){ returnthis.questionIndex===this.questions.length; } function Question(text, choices, answer){ this.text=text; this.choices= choices; this.answer= answer; }
Question.prototype.isCorrectAnswer=function(choice){ returnthis.answer=== choice; } function populate(){ if(quiz.isEnded()){ showScores(); } else{ // show question varelement=document.getElementById(\"question\"); element.innerHTML=quiz.getQuestionIndex().text; // show options var choices =quiz.getQuestionIndex().choices; for(var i = 0; i <choices.length; i++){ varelement=document.getElementById(\"choice\" + i); element.innerHTML= choices[i];
guess(\"btn\" + i, choices[i]); } showProgress(); } }; function guess(id, guess){ varbutton=document.getElementById(id); button.onclick=function(){ quiz.guess(guess); populate(); } }; functionshowProgress(){ varcurrentQuestionNumber=quiz.questionIndex+ 1; varelement=document.getElementById(\"progress\"); element.innerHTML= \"Question \" +currentQuestionNumber+ \" of \"
+quiz.questions.length; }; functionshowScores(){ vargameOverHTML= \"<h1>Result</h1>\"; gameOverHTML+= \"<h2 id='score'> Your scores: \" +quiz.score+ \"</h2>\"; varelement=document.getElementById(\"quiz\"); element.innerHTML=gameOverHTML; }; // create questions here var questions =[ new Question(\"Hyper Text Markup Language Stand For?\",[\"JavaScript\", \"XHTML\",\"CSS\", \"HTML\"], \"HTML\"), new Question(\"Which language is used for styling web pages?\",[\"HTML\", \"JQuery\", \"CSS\", \"XML\"], \"CSS\"), new Question(\"Which is not a JavaScript Framework?\",[\"Python Script\", \"JQuery\",\"Django\", \"NodeJS\"], \"Django\"), new Question(\"Which is used for Connect To Database?\",[\"PHP\", \"HTML\", \"JS\", \"All\"], \"PHP\"), new Question(\"google.com is about..\",[\"Web Design\", \"Graphic Design\", \"SEO & Development\", \"None\"], \"All\")
]; // create quiz var quiz =new Quiz(questions); // display quiz populate(); Output
EXPERIMENT 4-WAP TO IMPLEMENT USER INTERFACE COMPONENTS. Solution importjava.awt.Color; importjava.awt.Graphics; importjava.awt.GridLayout; importjava.awt.Container; importjavax.swing.JFrame; importjavax.swing.JPanel; public class FirstSwingExampleextendsJPanel{ Colorcolor; public FirstSwingExample(Colorcolor){ this.color=color;
this.setBackground(Color.BLACK); this.setOpaque(true); //needed to ensure panel background is set } public void paintComponent(Graphics g){ super.paintComponent(g); //needed to ensure that panel background is set int width =getWidth(); int height =getHeight(); g.setColor(color); g.fillOval(0, 0, width, height); } public static void main(String args[]){ JFrame frame =newJFrame(\"Oval Sample\"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content =frame.getContentPane(); content.setBackground(newColor(180,230,255)); content.setLayout(newGridLayout(2, 2, 5 ,5)); Colorcolors[]={Color.RED,Color.BLUE,Color.GREEN,Color.YELLOW}
; for(Color c:colors){ FirstSwingExample panel =newFirstSwingExample(c); content.add(panel); } //validate must be done on the component that has the .add() and the layoutManager content.validate(); frame.setSize(300, 200); frame.setLocation(50,100); frame.setVisible(true); } } Output
EXPERIMENT 5-WAP WHICH USES OBJECTS AND CLASSES THAT MAINTAINS THE RECORDS OF STUDENTS. Solution importjava.util.*; public class Student { private String m_name; private intm_age; private String m_course; private String m_year; private String m_section; public Student( String name, int age, String course, String year, String section ) { m_name= name; m_age= age;
m_course= course; m_year= year; m_section= section; } public String getName() { returnm_name; } public intgetAge() { returnm_age; } public String getCourse() { returnm_course; }
public String getYear() { returnm_year; } public String getSection() { returnm_section; } public String toString() { return \"name: \" +m_name+ \", age: \" +m_age+ \", course: \" +m_course+ \", year: \" +m_year+ \", section: \" +m_section; } public static void main(String[]args) { ArrayList<Student> students =newArrayList<Student>();
Scanner input =new Scanner(System.in); intmenuChoice= 4; do{ System.out.println(\"\\t\\t\\tStudent Record Menu\"); System.out.println(\"\\t\\t1. Add Student\\t2. View Students\\t3. Search Student\\t4. Exit\"); try{ System.out.println(\"Enter a choice: \"); menuChoice=Integer.parseInt(input.nextLine()); }catch(NumberFormatException e){ continue; } if(menuChoice==1) { System.out.println(\"Full name:\"); String name =input.nextLine(); int age =-1;
do{ try{ System.out.println(\"Age:\"); age =Integer.parseInt(input.nextLine()); }catch(NumberFormatException e){ System.out.println(\"Enter a number!\"); continue; } }while(age <= 0); System.out.println(\"Course:\"); String course =input.nextLine(); System.out.println(\"Year:\"); String year =input.nextLine(); System.out.println(\"Section:\"); String section =input.nextLine(); Student student=new Student(name, age, course, year, section);
students.add(student); }elseif(menuChoice==2){ System.out.println(\"Students:\"); for(Student student: students) { System.out.println(student); } } }while(menuChoice<4); } } Output
EXPERIMENT 6-WAP TO REPRESENT METHOD OVERLOADING BY CHANGING DATA TYPE OF ARGUMENT. Solution class Adder{ static int add(int a,int b){returna+b;} static double add(double a, double b){returna+b;} } class TestOverloading2{ public static void main(String[]args){ System.out.println(Adder.add(11,11)); System.out.println(Adder.add(12.3,12.6)); }} Output
EXPERIMENT 7-WAP TO IMPLEMENT CONSTRUCTOR OVERLOADING. Solution public class Student { //instance variables of the class int id; String name; Student(){ System.out.println(\"this a default constructor\"); } Student(int i, String n){ id = i; name = n; } public static void main(String[]args){
//object creation Student s =new Student(); System.out.println(\"\\nDefault Constructor values: \\n\"); System.out.println(\"Student Id : \"+s.id + \"\\nStudent Name : \"+s.name); System.out.println(\"\\nParameterized Constructor values: \\n\"); Student student=new Student(10, \"David\"); System.out.println(\"Student Id : \"+student.id + \"\\nStudent Name : \"+student.name); } } Output
EXPERIMENT 8-WAP TO SHOW THE USE OF STATIC VARIABLE AND STATIC METHOD. Solution public class Demo{ public static void main(String args[]){ Student s1 = new Student(); s1.showData(); Student s2 = new Student(); s2.showData(); //Student.b++; //s1.showData(); } } class Student { int a; //initialized to zero static int b; //initialized to zero only when class is loaded not for each object created.
Student(){ //Constructor incrementing static variable b b++; } public void showData(){ System.out.println(\"Value of a = \"+a); System.out.println(\"Value of b = \"+b); } //public static void increment(){ //a++; //} Output
EXPERIMENT 9-WAP TO SHOW USES THE SUPER KEYWORD. Solution class Animal{ Animal(){System.out.println(\"animal is created\");} } class Dog extends Animal{ Dog(){ super(); System.out.println(\"dog is created\"); } } class TestSuper3{ public static void main(String args[]){ Dog d=new Dog(); }} Output
EXPERIMENT 10-WAP TO IMPLEMENT THE CONCEPT OF MULTILEVEL INHERITANCE. Solution class Car{ public Car() { System.out.println(\"Class Car\"); } public void vehicleType() { System.out.println(\"Vehicle Type: Car\"); } } class Maruti extends Car{ public Maruti() { System.out.println(\"Class Maruti\");
} public void brand() { System.out.println(\"Brand: Maruti\"); } public void speed() { System.out.println(\"Max: 90Kmph\"); } } public class Maruti800 extends Maruti{ public Maruti800() { System.out.println(\"Maruti Model: 800\"); } public void speed() { System.out.println(\"Max: 80Kmph\"); }
public static void main(String args[]) { Maruti800 obj=new Maruti800(); obj.vehicleType(); obj.brand(); obj.speed(); } } Output Class Car Class Maruti Maruti Model: 800 Vehicle Type: Car Brand: Maruti Max: 80Kmph
EXPERIMENT 11-WAP TO IMPLEMENT THE CONCEPT OF INTERFACE. Solution interface printable{ void print(); } class A6 implements printable{ public void print(){System.out.println(\"Hello\");} public static void main(String args[]){ A6 obj=new A6(); obj.print(); } } Output Compile by: javac A6.java
Run by: java A6 Hello
EXPERIMENT 12-WAP TO SHOW THE USE OF MULTITHREADING. Solution import java.applet.Applet; import java.awt.Graphics; import java.awt.*; /*<applet code=\"AppletLifeCycle.class\" width=\"350\" height=\"150\"></applet>*/ public class AppletLifeCycle extends Applet { public void init() { setBackground(Color.CYAN); System.out.println(\"init() called\"); } public void start(){ System.out.println(\"Start() called\"); } public void paint(Graphics g){ System.out.println(\"Paint(() called\"); } public void stop() { System.out.println(\"Stop() Called\"); } public void destroy() { System.out.println(\"Destroy)() Called\"); } }
Search