How do I call a class in a main class
This program I have made measures the area of the room.
Now i want to create two classes. b-(
This is the original coding I made that works perfectly. But here I put everything in one class:
Code Java:
import javax.swing.JOptionPane;
public class RoomOne
{
public static void main(String[] args) throws Exception
{
//Declaration of strings
String firstNumber;
String secondNumber;
int numberOne=10;
int numberTwo=20;
int finalAnswer=numberOne*numberTwo;
JOptionPane.showMessageDialog(null, "The area of the room is: " + finalAnswer + " sqaure feet", "Room Measurement", JOptionPane.INFORMATION_MESSAGE);
{
System.exit(0);
}
}
}
I want to have two classes, the main class, and a secondary class.
The secondary class should contain the entire coding. I want to be able to call the secondary class in the main class. How do I do that?
Re: How do I call a class in a main class
Your first step is to put that all in a method, then call it from the main you already have. When you have that working, then just do the same thing in another class.
Re: How do I call a class in a main class
Hey this is initail level of codding... please read the java book.
For your reference i am attaching the code.. But please take care....
Code Java:
package com.java.main;
import com.java.main.RoomTwo;
public class RoomOne {
public static void main(String[] args) throws Exception {
RoomTwo r2 = new RoomTwo();
r2.roomDetail();
}
}
Code Java:
package com.java.main;
import javax.swing.JOptionPane;
public class RoomTwo {
public void roomDetail() throws Exception {
// Declaration of strings
String firstNumber;
String secondNumber;
int numberOne = 10;
int numberTwo = 20;
int finalAnswer = numberOne * numberTwo;
JOptionPane.showMessageDialog(null, "The area of the room is: "
+ finalAnswer + " sqaure feet", "Room Measurement",
JOptionPane.INFORMATION_MESSAGE);
{
System.exit(0);
}
}
}