You are on page 1of 3

Name: M.

Awais Amin Gill Sap ID: 70110264 Assignment #: 01


Course: Java Development Date: 20-10-2021

Question 1:
package labassignment1;
import java.util.Scanner;
/**
*
* @author Awais
*/
public class Lab_Q1 {
public static void main(String args[]) {
float temp;
String[]
city={"Lahore","Sargodha","Kasur","Sialkot","Gojra","Bhalwal","Faisalabad","Raiwind","Chiniot","khush
aab"};
Scanner sc =new Scanner(System.in);
float[] city_temp= new float[10];
char choice;
System.out.println("In which format do you want to enter temperature? c/f");
choice = sc.next().charAt(0);

for(int i=0;i<10;i++) {
System.out.print("Enter temperature of " + city[i] + " in Celcius: ");
city_temp[i]=sc.nextFloat();
}
if(choice == 'c') {
for(int i=0; i<10; i++) {
temp = ((city_temp[i] * 9/5) + 32);
System.out.println("Temperature of city " + city[i] + " is " + temp + " degree Farenheit");
}
}
else if (choice == 'f') {
for(int i=0; i<10; i++) {
temp = ((city_temp[i] - 32) * 5/9);
System.out.println("Temperature of city " + city[i] + " is " + temp + " degree Celcius");
}
}
else{
System.out.println("You have enter wrong choice.");
}

}
}
Output:

Question 2:
package labassignment1;
import javax.swing.*;
/**
*
* @author Awais
*/
public class Lab_Q2 {

public static void main(String[] args) {


String str = JOptionPane.showInputDialog("Enter your name: ");
int choice = JOptionPane.showConfirmDialog(null, "Do you want to show your name?");
if (choice == 0){
JOptionPane.showMessageDialog(null, str,"Your Name",JOptionPane.PLAIN_MESSAGE);
}
JOptionPane.showMessageDialog(null, "This is info Dialog Box.", "Title",
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "This is warning Dialog Box.","Title",
JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(null, "This is error Dialog Box.","Title",
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "This is question Dialog Box.","Title",
JOptionPane.QUESTION_MESSAGE);
System.out.println("Thank You!");
System.exit(0);
}
}

Output:

You might also like