Hello !here are two java codes from my OOP assingments.
1.Converts temparature from Fareinheit scale to celcius scale
2.Calculates the magnitude of a vector
1.Converts temparature from Fareinheit scale to celcius scale
2.Calculates the magnitude of a vector
/**A program that converts temparature
* from degrees fahreinheit
* to degrees celcius
*/
import javax.swing.JOptionPane;
public class FareinheitToCelsiusGUI
{
public static void main(String args[])
{
float temp_fahrt;
double temp_cels;
String x=JOptionPane.showInputDialog(null,"ENTER THE DEGREE IN FAHREINHET","INPUT TEMPARATURE",JOptionPane.INFORMATION_MESSAGE);
temp_fahrt=Float.parseFloat(x);
temp_cels=(5.0/9.0)*(temp_fahrt-32.0);//formula to convert degrees
JOptionPane.showMessageDialog(null,+temp_cels+" Celcius","TEMPARATURE CONVERSION RESULT",JOptionPane.ERROR_MESSAGE);// the result is displayed here
}
}
Program 2
import javax.swing.JOptionPane;
public class VextorLenght{
public static void main(String []args)
{
JOptionPane.showMessageDialog(null,"A VECTOR IS THE FORM\n r=ai+bj+ck\nENTER THE VALUES OF a b and c","INSTRUCTIONS",JOptionPane.INFORMATION_MESSAGE);
String T=JOptionPane.showInputDialog(null,"ENTER THE VALUE OF a","COEFFICIENT OF COMPONENT i",JOptionPane.INFORMATION_MESSAGE);
int i=Integer.parseInt(T);
String R=JOptionPane.showInputDialog(null,"ENTER THE VALUE OF b","COEFFICIENT OF COMPONENT j",JOptionPane.INFORMATION_MESSAGE);
int j=Integer.parseInt(R);
String S=JOptionPane.showInputDialog(null,"ENTER THE VALUE OF c","COEFFICIENT OF COMPONENT k",JOptionPane.INFORMATION_MESSAGE);
int k=Integer.parseInt(S);
double magnitude=Math.sqrt((i*i)+(j*j)+(k*k));
JOptionPane.showMessageDialog(null,+magnitude+" units","RESULT",JOptionPane.WARNING_MESSAGE);
}
}
More on java programming
No comments:
Post a Comment