You are on page 1of 16

Pir Mehr Ali Shah

Arid Agriculture University, Rawalpindi


Office of the controller of Examinations
Final Exam (Practical)/ Spring 2020 (Paper Duration 48 hours)
To be filled by Teacher

Course No.: ………… CS-432………Course Title:………… Modern Programming Languages (MPL)……………


Total Marks:……….…… 20…………………Date of Exam:……………..………………............................
Degree: …………… BSCS/BSIT ……………….Semester:…… 6th ……… Section:………... Morning/Evening
……………..
Marks
Q.No. 1 2 3 4 5 6 7 8 9 10 Obtained/
TotalMarks
Marks
Obtaine
d
Total Marks in Words:
Name of the teacher:
Who taught the course: Signature of teacher / Examiner:

To be filled by Student

Registration No.: …17 ARID 2015……………………………………….……… Name:…MUHAMMAD UMER


…………………………………………………..

Answer the following questions.

Question # 1 (Marks: 08)

Explain your semester project in the light of Software Development Life Cycle (SDLC). [Marks: 8]

i. What you have done in Requirement gathering and analysis phase.

ii. What problems you have faced in Design phase.

iii. What kind of tools and techniques you adopted in Implementation or coding phase.

iv. What problems you faced in Testing phase and What steps you have performed in

Deployment phase (if deployed).

Answer:
Part 1:
Online Food Order App:
Requirement gathering and analysis phase:
As it is the most important phase in software development life cycle, I try my level best do collect
and gather information and analysis the situation.
I did a fine analysis on every aspects and try to avoid any future conflicts.

Part 2:
Design Phase:
This is an important stage of app design as it is compulsory to have a good design of your app.
With the help of 1st phase I design my app quite well.
Although I had face some difficulty in making design as many other apps were using the same
design. So to make my app different from others I put unique styling.

Part 3:
Implementation and Coding Phase:

In this step, the actual implementation and coding for app takes place. For that we use different
tools and techniques to make our implementation effective.
Part d:
Testing Phase:
I firstly test my app on smaller group of people so that I may get an idea about how to move on.
Then after successful running of my app I further increase my testing on larger group.

Development Phase:
I have developed my app because of successful test on some group of people. I had put this app on
Google play store in order to get benefit of my hard work and to provide service to others.
Question # 2 Answer the followings using Java Code

a. How you will read an MS Excel file in Java. Read an MS Excel File in Java

b. How images are displayed in Java jFrame

c. How audio is played in Java jFrame

d. How video clip is played in Java jFrame

e. Create an animated Cartoon in Java, goto Google for help

f. Create a text file in Java, then Write complete Java code to Write the following text to
Text file

“Java is an object-oriented programming language developed by Sun Microsystems,


a company best known for its high-end Unix workstations. Modelled after C++, the
Java language was designed to be small, simple, and portable across platforms and
operating systems, both at the source and at the binary level”

Finally, write Java code to read the text from the text file and display it on the jTextFields.

============================= GOOD LUCK =============================

Question 2:

Part a:

Apache POI (Poor Obfuscation Implementation) is a Java API for reading and writing
Microsoft Documents in both formats .xls and .xlsx. It contains classes and interfaces.
The Apache POI library provides two implementations for reading excel files:

Java code:

1. import java.io.File;  
2. import java.io.FileInputStream;  
3. import java.io.IOException;  
4. import org.apache.poi.hssf.usermodel.HSSFSheet;  
5. import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
6. import org.apache.poi.ss.usermodel.Cell;  
7. import org.apache.poi.ss.usermodel.FormulaEvaluator;  
8. import org.apache.poi.ss.usermodel.Row;  
9. public class ReadExcelFileDemo  
10. {  
11. public static void main(String args[]) throws IOException  
12. {  
13. //obtaining input bytes from a file  
14. FileInputStream fis=new FileInputStream(new File("C:\\demo\\student.xls"));  
15. //creating workbook instance that refers to .xls file  
16. HSSFWorkbook wb=new HSSFWorkbook(fis);   
17. //creating a Sheet object to retrieve the object  
18. HSSFSheet sheet=wb.getSheetAt(0);  
19. //evaluating cell type   
20. FormulaEvaluator formulaEvaluator=wb.getCreationHelper().createFormulaEvalua
tor();  
21. for(Row row: sheet)     //iteration over row using for each loop  
22. {  
23. for(Cell cell: row)    //iteration over cell using for each loop  
24. {  
25. switch(formulaEvaluator.evaluateInCell(cell).getCellType())  
26. {  
27. case Cell.CELL_TYPE_NUMERIC:   //field that represents numeric cell type  
28. //getting the value of the cell as a number  
29. System.out.print(cell.getNumericCellValue()+ "\t\t");   
30. break;  
31. case Cell.CELL_TYPE_STRING:    //field that represents string cell type  
32. //getting the value of the cell as a string  
33. System.out.print(cell.getStringCellValue()+ "\t\t");  
34. break;  
35. }  
36. }  
37. System.out.println();  
38. }  
39. }  
40. }  

Part b:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

class drawImage extends JPanel {

BufferedImage[] b = new BufferedImage[2];

public drawImage() {
try {
b[0] = ImageIO.read(new File("img/gameOn.png"));
b[1] = ImageIO.read(new File("img/gameOff.png"));
} catch (IOException e) {

e.printStackTrace();
}

public void paintComponent(Graphics g) {


super.paintComponent(g);

g.drawImage(b[0], 0, 0, null);

public void setNextImage(BufferedImage image) {

b[0] = image;

repaint();
}

public BufferedImage getB0() {


return b[0];
}

public BufferedImage getB1() {


return b[1];
}

}// end drawImage

class clickedListener implements ActionListener {

BufferedImage pre = new drawImage().getB0();


BufferedImage next = new drawImage().getB1();

@Override
public void actionPerformed(ActionEvent e) {

new drawImage().setNextImage(next);

public class buttonFrame {


public static void main(String[] args) throws IOException {
JFrame jf = new JFrame("Button & Frame");
JButton btn = new JButton("Click");

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setLayout(new GridLayout(2, 0));
jf.add(new drawImage());
jf.add(btn);
jf.setSize(200, 250);

btn.addActionListener(new clickedListener());

Part c:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class MyJFrame extends JFrame


{
public JButton play, choose;
private String file;
public static MyJFrame instance;

public MyJFrame()
{
this.setSize(400,400);
this.setTitle("Wave audio player");
this.setComponents();
this.setListeners();
}

public void setComponents(){

public void setListeners(){

public static Frame setup(){


MyJFrame window = new MyJFrame();
window.setVisible(true);
window.setLocationRelativeTo(null);
return window;
}

public static void main(String args[]){


MyJFrame.setup();
}

}
Part d:

public void Player() {

try{
//create a player to play the media specified in the URL

Player mediaPlayer = Manager.createRealizedPlayer(new


URL("C:\\Users\\Michael\\Downloads\\mike.jar"));

Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);

//get the components for the video and the playback controls
Component video = mediaPlayer.getVisualComponent();
Component controls = mediaPlayer.getControlPanelComponent();

if ( video != null )
jPanel1.add( video, BorderLayout.CENTER ); //add video component
if ( controls != null )
jPanel1.add( controls, BorderLayout.SOUTH ); //add controls

mediaPlayer.start(); //start playing the media clip


} //end try
catch ( NoPlayerException noPlayerException ){
JOptionPane.showMessageDialog(null, "No media player found");
} //end catch
catch ( CannotRealizeException cannotRealizeException ){
JOptionPane.showMessageDialog(null, "Could not realize media player.");
} //end catch
catch ( IOException iOException ){
JOptionPane.showMessageDialog(null, "Error reading from the source.");
} //end catch

Part e:

For instance, to paint a blue circle centered at a given location, you need to
write the following code:

1 private java.awt.Color color = java.awt.Color.BLUE;   // The color of the


ball
2 private java.awt.Point location = new java.awt.Point(23, 84);  // the
location of the center of the ball
3 private int radius = 10;   // the radius of the ball

4    

5 public void paintComponent(Graphics g) {
6     super.paintComponent(g);   // paint whatever normally gets painted.
7     g.setColor (color);  // set the color to paint with
8     g.fillOval (location.x-radius, location.y-
radius, 2*radius, 2*radius); // paint a circle onto the graphics object
centered on location and with defined radius.
}

Part f:
import java.io.*;

import javax.swing.*;

import java.util.*;

public class Microsystems extends javax.swing.JFrame {

public Microsystems() {

initComponents();

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jTextField1 = new javax.swing.JTextField();

jTextField2 = new javax.swing.JTextField();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jTextField1.setToolTipText("");

jTextField1.setDoubleBuffered(true);

jTextField1.setDragEnabled(true);

jTextField2.setHorizontalAlignment(javax.swing.JTextField.LEFT);
jButton1.setText("Write to file");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

});

jButton2.setText("Read from file");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 535,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addGroup(layout.createSequentialGroup()

.addGap(41, 41, 41)

.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 515,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(46, Short.MAX_VALUE))

.addGroup(layout.createSequentialGroup()
.addGap(253, 253, 253)

.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 123,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addGroup(layout.createSequentialGroup()

.addGap(238, 238, 238)

.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 123,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 101,


Short.MAX_VALUE)

.addGap(28, 28, 28)

.addComponent(jButton1)

.addGap(55, 55, 55)

.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 143,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addComponent(jButton2)

.addContainerGap(16, Short.MAX_VALUE))

);

jTextField1.getAccessibleContext().setAccessibleParent(null);

pack();

}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

try {

FileWriter myWriter = new FileWriter("filename.txt");

myWriter.write(jTextField1.getText());

myWriter.close();

JOptionPane.showMessageDialog(null,"Successfully saved");

} catch (IOException e) {

e.printStackTrace();

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String total ="";

try {

File myObj = new File("filename.txt");

Scanner myReader = new Scanner(myObj);

while (myReader.hasNextLine()) {

String data = myReader.nextLine();

total +=data;

jTextField2.setText(total );

myReader.close();

} catch (FileNotFoundException e) {
e.printStackTrace();

public static void main(String args[]) {

try {

for (javax.swing.UIManager.LookAndFeelInfo info :


javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(Microsystems.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Microsystems.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Microsystems.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Microsystems.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);

}
//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Microsystems().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JTextField jTextField1;

private javax.swing.JTextField jTextField2;

// End of variables declaration

You might also like