Learning Objects and Classes

Questions and advice sought.

Page 1 of 1

10 Replies - 1553 Views - Last Post: 21 November 2009 - 07:54 PM Rate Topic: -----

#1 Sollek  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Learning Objects and Classes

Post icon  Posted 19 November 2009 - 08:52 PM

Now that I've last week's assignment done I've to start this weeks and quite a bit late as well to boot... :wub: College!
Here's steps I'm asked to do that I either have questions on or would like to gain added input for.

Here's my 3rd Week:
import javax.swing.JOptionPane;
import programDisplay.java;
public class Main_Class {
	public static void main(String[] args) {
		
		String result;
		int number1;
		int number2;
		
		if(determineOver100(number1,number2))
		{
			number1-=100;
			number2-=100;
			displayResult("Both over 100");
		} else
			displayResult("Both not over 100");
		result = calcSum(number1, number2);
		//Pass the results to the generic display
		displayResult(result);
				
		result = calcProduct(number1,number2);
		displayResult(result);
		
		result = calcDiff(number1,number2);
		displayResult(result);
		
		result = determineMin(number1,number2);
		displayResult(result);
		
		result = determineMax(number1,number2);
		displayResult(result);
		
		result = calcAvg(number1,number2);
		displayResult(result);
	}
	

	
	public static int getFirstNumber()
	{
		String firstNumber;
		int num1;
		firstNumber = JOptionPane.showInputDialog("Enter first integer");
		num1 = Integer.parseInt(firstNumber);
		return num1;
	}	
	public static int getSecondNumber()
	{
		String secondNumber;
		int num2;
		secondNumber = JOptionPane.showInputDialog("Enter second integer");
		num2 = Integer.parseInt(secondNumber);
		return num2;
	}
	
	//values must be passed into the method
	public static String calcSum(int number1, int number2)
	{   int sum;
		String result;
		sum =  number1 + number2;
		//Note the complete formatting for the output
		result = number1 + " + " + number2 + "=" + sum;
		return result;
	}
	
	public static String calcDiff(int number1, int number2)
	{   double diff;
		String result;
		diff =  number1 / number2;
		//Note the complete formatting for the output
		result = number1 + " / " + number2 + "=" + diff;
		return result;
	}
	
	public static String calcAvg(int number1, int number2)
	{   double Avg;
		String result;
		Avg =  (number1 + number2)/2.0;
		result = "(" + number1 + "+" + number2 + ")" + "/2.0" + "=" + Avg;
		return result;
	}
	
	public static String calcProduct(int number1, int number2)
	{   int Product;
		String result;
		Product =  number1 * number2;
		result = number1 + " X " + number2 + "=" + Product;
		return result;
	}
	
	public static String determineMin(int number1, int number2)
	{   
		String result;
		int min;
		if (number1 > number2)
			min = number2;
		else
			min = number1;
		//The above 5 lines could be replaced with the following line
		//int min = (number1 > number2) ? number2 : number1;
		result = "The minimum is: " + min;
		return result;
	}

	public static String determineMax(int number1, int number2)
	{   
		String result;
		int max;
		if (number1 < number2)
			max = number2;
		else
			max = number1;
		result = "The maximum is: " + max;
		return result;
	}
	
	public static boolean determineOver100(int number1, int number2)
	{   
		if (number1 > 100 && number2 > 100)
			return true;
		else
			return false;
		//The above  lines could be replaced with the following line
		//return (number1 > 100 && number2 > 100) ? true : false;
	}
	
	public static void displayResult(String msg)
	{
		JOptionPane.showMessageDialog(null,msg,"Results",JOptionPane.PLAIN_MESSAGE);
	}
}


Posted Image
To "move" the methods could I drag and drop from Main_Class\calcSum or Main_Class\calcAverage function to numberOperations.java?

And if I AM able to do as stated I'm still not quite understanding how to instantiate

STEP 2: Create Classes

Create the following classes and then move the methods defined in the Main_Class class to the appropriate class. Remember, to keep logically related attributes and operations in the same class. Determine if each class, or method, should be declared as a static or instance class.

* Program Display
* User Input
* Number Operations
* Input Validation





STEP 3: Create a Main Method

Modify the main method so that it only declares the necessary variables and contains the main program control loop. You will have to create objects for each of the defined instance classes. Inside the controlling loop invoke each of the object methods as appropriate to reproduce the behavior found in the week 3 lab.

No other processing except program control will be done in the main method.


Any additional assistance would be wonderful if someone has time to play forum tag or contact me via msn/aim/yahoo listed in profile would prefer to use forums as to not violate any rules set forth. And to give others a chance to learn with me.

Thanks in advance to all the mentors and teachers amongst you.
Will check back frequent!
-Brandon

This post has been edited by Sollek: 20 November 2009 - 07:36 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Learning Objects and Classes

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Learning Objects and Classes

Posted 19 November 2009 - 09:40 PM

You are learning Objects and Classes and you ask basic, really basic, question
and you checked the "Intermediate" tag ?
Was This Post Helpful? 0
  • +
  • -

#3 Sollek  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Re: Learning Objects and Classes

Posted 20 November 2009 - 12:47 PM

View Postpbl, on 19 Nov, 2009 - 08:40 PM, said:

20, 2009
You are learning Objects and Classes and you ask basic, really basic, question
and you checked the "Intermediate" tag ?


Likely a good point after the fact I realized what I'd done. 4 weeks in course half way through to 8 wasn't quite sure what would classify as "intermediate"

Note: The phrase "instantiating a class" means the same thing as "creating an object." When you create an object, you are creating an "instance" of a class, therefore "instantiating" a class.
Source:
http://java.sun.com/...ctcreation.html retrieved on November 20, 2009 didn't realize there was another term for it...

My apologies for my newbness.

This post has been edited by Sollek: 20 November 2009 - 12:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 Sollek  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Re: Learning Objects and Classes

Posted 20 November 2009 - 07:52 PM

Anyone able to lend a hand? I'm unable to figure out how to call the separate classes from inside the main class... I've the code written up just not quite certain how to get it to perform as I want...
Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Learning Objects and Classes

Posted 20 November 2009 - 07:55 PM

classes are in separate .java files. You then create object instances in main and use them for whatever.

Is there something specific you need help with? Your OP is a little hard to decipher.
Was This Post Helpful? 1
  • +
  • -

#6 Sollek  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Re: Learning Objects and Classes

Posted 20 November 2009 - 10:22 PM

Heya Kya,
Thanks for the help thus far I'm starting to get my program together. Writing it was a somewhat easy task. However modularizing it was a whole different ball game.

I'm trying to piece together two objects

public class InputValidation {
	public void validateInput() {
		NumberOperations NumOp = new NumberOperations();
		ProgramDisplay pd = new ProgramDisplay();
		if (NumOp.getNumber1() > 100 && NumOp.getNumber2() > 100)
			{
				NumOp.setNumber1(NumOp.getNumber1() - 100);
				NumOp.setNumber2(NumOp.getNumber2() - 100);
				pd.displayResult("Both numbers were > 100, so now they are " + NumOp.getNumber1() + " and " + NumOp.getNumber2() + " respectively");
			}
			else
				pd.displayResult("Both numbers are not > 100");
		//OK, now you have to write the code for negative numbers
			
	}
	public void validateInput() {
		NumberOperations NumOp = new NumberOperations();
		ProgramDisplay pd = new ProgramDisplay();
		if (NumOp.getNumber1() < 0 && NumOp.getNumber2() < 0)
			{
				NumOp.setNumber1(NumOp.getNumber1() + 200);
				NumOp.setNumber2(NumOp.getNumber2() + 200);
				pd.displayResult("Both numbers were < 0, so now they are " + NumOp.getNumber1() + " and " + NumOp.getNumber2() + " respectively");
			}
			else
				pd.displayResult("Both numbers are < 0");
			
	}
}



Hints for Lab 4
Hints for Lab 4
You need to create four classes based on Step 2:
ProgramDisplay
UserInput
NumberOperations
InputValidation
To create a class, Click File->New->Class but DO NOT check the box for “public static void main(String[] args)

For ProgramDisplay, you should see:
public class ProgramDisplay {
}
ProgramDisplay
The ProgramDisplay class will contain two methods from lab 3: displayInstructions and displayResult. Just copy them from lab 3.  No constructor is needed.
UserInput
For the UserInput class, we don’t need to create a constructor because we are not passing data into the class.  Continuing my example from lab 3, let’s move the method to get the first number into the class, instantiate the object in main, and then get the first number. Notice that the method does not contain the word “static”.
public class UserInput {
	public int getFirstNumber()
	{
		String strNum;
		int num;
		strNum = JOptionPane.showInputDialog("Enter first integer");
		num = Integer.parseInt(strNum);
		return num;
	}
}
In main, you have to instantiate the object and then call the method in the class so in main you will have:
UserInput ui = new UserInput();
number1 = ui.getFirstNumber();
NumberOperations
The NumberOperations class will contain two variables, number1 and number2 .  These will be used in the calculations.  The main decision in declaring the variables is whether they will be static or not. If they are static, then other objects can change the values.  Because in my example of validateInput(), I want to change the values in number1 and number2 , I will make them static:
static int number1;
static int number2;
Because you will create a loop that allows you to enter multiple sets of numbers, you need a way to put new numbers in your NumberOperations object every time you go through the loop.  To do this, you need two methods: setNumber1and setNumber2.  For example:
public void setNumber1(int num){
	number1 = num;
}
Depending on how you write your program, you may need the corresponding “get” methods.  I have an example of using them down in validateInput.  For number1 it would be:
public int getNumber1(){
	return number1;
}
Once the object contains both the integer values, the methods for the NumberOperations object are much easier to create.  For example:
public String calcSum() {
	int sum;
	String result;
	sum =  number1 + number2;
	result = number1 + "+" + number2 + "=" + sum;
	return result;
}
InputValidation
This is part of the validation.  Naturally, the name of the objects may be different.
public void validateInput() {
	NumberOperations NumOp = new NumberOperations();
	ProgramDisplay pd = new ProgramDisplay();
	if (NumOp.getNumber1() > 100 && NumOp.getNumber2() > 100)
		{
			NumOp.setNumber1(NumOp.getNumber1() - 100);
			NumOp.setNumber2(NumOp.getNumber2() - 100);
			pd.displayResult("Both numbers were > 100, so now they are " + NumOp.getNumber1() + " and " + NumOp.getNumber2() + " respectively");
		}
		else
			pd.displayResult("Both numbers are not > 100");
	//OK, now you have to write the code for negative numbers

}
Main Method
Now that you have the classes built, do the following in the main method:
Create the variables that you will need
Instantiate objects based on the four classes above
From this point, each statement will reference one of the above four objects
Display the Instructions
do
Get the numbers
Set the numbers in your NumberOperations object
Call validateInput
Use your NumberOperations object to calculate the sum and store it in a String variable
Use your ProgramDisplay object to display the result
Call the other methods in you Number Operations object
while the user wants to continue



If you hap to have MSN, Aim, Yahoo messengers your welcome to contact me there if that would be of much use. Thanks again Kya

In short I'm trying to replicate what I've done with lab3 into lab 4 using separate classes.

Here's lab 3 for proof that's done sir,
import javax.swing.JOptionPane;
public class Main_Class {
	public static void main(String[] args) {
		
		String result;
		int number1;
		int number2;

		DisplayInstructions();	
		number1 = getFirstNumber();		//get the first number
		number2 = getSecondNumber();	//Get the second number
		
		if(determineOver100(number1,number2))
		{
			number1-=100;
			number2-=100;
			displayResult("Both over 100");
		} else
			displayResult("Both not over 100");
		result = calcSum(number1, number2);
		//Pass the results to the generic display
		displayResult(result);
				
		result = calcProduct(number1,number2);
		displayResult(result);
		
		result = calcDiff(number1,number2);
		displayResult(result);
		
		result = determineMin(number1,number2);
		displayResult(result);
		
		result = determineMax(number1,number2);
		displayResult(result);
		
		result = calcAvg(number1,number2);
		displayResult(result);
	}
	
	public static void  DisplayInstructions()
	{
		JOptionPane.showMessageDialog(null,"Enter Numbers\nPress Ok After Each\nView Results", "Instructions", JOptionPane.INFORMATION_MESSAGE);
		JOptionPane.showMessageDialog(null,"Created By: Brandon Berne\nClass: CiS247\nDate: 11/18/09", "About", JOptionPane.INFORMATION_MESSAGE);
	}
	
	public static int getFirstNumber()
	{
		String firstNumber;
		int num1;
		firstNumber = JOptionPane.showInputDialog("Enter first integer");
		num1 = Integer.parseInt(firstNumber);
		return num1;
	}	
	public static int getSecondNumber()
	{
		String secondNumber;
		int num2;
		secondNumber = JOptionPane.showInputDialog("Enter second integer");
		num2 = Integer.parseInt(secondNumber);
		return num2;
	}
	
	//values must be passed into the method
	public static String calcSum(int number1, int number2)
	{   int sum;
		String result;
		sum =  number1 + number2;
		//Note the complete formatting for the output
		result = number1 + " + " + number2 + "=" + sum;
		return result;
	}
	
	public static String calcDiff(int number1, int number2)
	{   double diff;
		String result;
		diff =  number1 / number2;
		//Note the complete formatting for the output
		result = number1 + " / " + number2 + "=" + diff;
		return result;
	}
	
	public static String calcAvg(int number1, int number2)
	{   double Avg;
		String result;
		Avg =  (number1 + number2)/2.0;
		result = "(" + number1 + "+" + number2 + ")" + "/2.0" + "=" + Avg;
		return result;
	}
	
	public static String calcProduct(int number1, int number2)
	{   int Product;
		String result;
		Product =  number1 * number2;
		result = number1 + " X " + number2 + "=" + Product;
		return result;
	}
	
	public static String determineMin(int number1, int number2)
	{   
		String result;
		int min;
		if (number1 > number2)
			min = number2;
		else
			min = number1;
		//The above 5 lines could be replaced with the following line
		//int min = (number1 > number2) ? number2 : number1;
		result = "The minimum is: " + min;
		return result;
	}

	public static String determineMax(int number1, int number2)
	{   
		String result;
		int max;
		if (number1 < number2)
			max = number2;
		else
			max = number1;
		result = "The maximum is: " + max;
		return result;
	}
	
	public static boolean determineOver100(int number1, int number2)
	{   
		if (number1 > 100 && number2 > 100)
			return true;
		else
			return false;
		//The above  lines could be replaced with the following line
		//return (number1 > 100 && number2 > 100) ? true : false;
	}
	
	public static void displayResult(String msg)
	{
		JOptionPane.showMessageDialog(null,msg,"Results",JOptionPane.PLAIN_MESSAGE);
	}
}



Well folks it's now 12:40 am EST Sadly I've Work in the morn so I'll be seeing you all, well this thread bright and early around 9am before work. Thanks to all people with added input and or questions.

-Brandon

Attached File(s)


This post has been edited by Sollek: 20 November 2009 - 10:39 PM

Was This Post Helpful? 0
  • +
  • -

#7 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Learning Objects and Classes

Posted 20 November 2009 - 10:44 PM

I'm trying to get a sense of what the actual problem is. Could you boil it down to a single sentence. I understand that there is an issue of utilizing separate classes to achieve the same results as in lab 3. Where exactly are you having problems?

From the problem statement, pseudo-code would look something like this:

public static void main(String[] args){
	//create the 4 objects
	ProgramDisplay pg = new ProgramDisplay();
	UserInput input =  new UserInput();
	NumberOperations num = new NumberOperations();
	InputValidation valid = new InputValidation();
	//do stuff
}




It seems to me that each object needs others to complete its task. The question is, should they all be handled in main or can you create objects within the others for simplicity. I don't know. Based on the description it says create all four in main, but then it says to reference only objects from hence forth. It would make sense for the input object to call validation, etc...
Was This Post Helpful? 0
  • +
  • -

#8 Sollek  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Re: Learning Objects and Classes

Posted 20 November 2009 - 10:52 PM

First issue I'm trying to solve:
The method getFirstNumber() is undefined for the type UserInput
The method getSecondNumber() is undefined for the type UserInput
It's declared int type... yes is undefined?
import javax.swing.JOptionPane;

	public class UserInput {
		public int getFirstNumber()
		{
			String strNum;
			int num;
			strNum = JOptionPane.showInputDialog("Enter first integer");
			num = Integer.parseInt(strNum);
			return num;
		}
		public int getSecondNumber()
		{
			String strNum;
			int num;
			strNum = JOptionPane.showInputDialog("Enter second integer");
			num = Integer.parseInt(strNum);
			return num;
		}
	}


Pardon me for confusing the crap out of everyone it would have helped to display problem scenario:

Scenario/Summary

This week we are going continue our evolution of NumberGames program by breaking up the existing code into classes and then creating objects of those classes.

The behavior and output of this program should be identical to the Week 3 program. From the users perspective, the two programs should be exactly the same.
STEP 1: Create a New Project
Back to top

Create a new project and copy the Week 3 lab files into the project.
STEP 2: Create Classes

Create the following classes and then move the methods defined in the Main_Class class to the appropriate class. Remember, to keep logically related attributes and operations in the same class. Determine if each class, or method, should be declared as a static or instance class.

* Program Display
* User Input
* Number Operations
* Input Validation
STEP 3: Create a Main Method

Modify the main method so that it only declares the necessary variables and contains the main program control loop. You will have to create objects for each of the defined instance classes. Inside the controlling loop invoke each of the object methods as appropriate to reproduce the behavior found in the week 3 lab.

No other processing except program control will be done in the main method.

This post has been edited by Sollek: 20 November 2009 - 10:56 PM

Was This Post Helpful? 0
  • +
  • -

#9 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Learning Objects and Classes

Posted 20 November 2009 - 10:55 PM

That makes more sense. Program display can be static since it only output some info to the user. User input should be instantiated and it will call number operations and input validation, both of which will have their own instance object within User Input.

Once you have the implementation down, we could revisit numberops and validation. Depending on how you set it up ,it could also be static.
Was This Post Helpful? 1
  • +
  • -

#10 Sollek  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Re: Learning Objects and Classes

Posted 21 November 2009 - 02:27 PM

Making some progress a few kinks left to work out yet but thanks a load for all the help its wonderful to have people to bounce theories/ideas off of and even greater a blessing to have the opportunity to be corrected by seasoned vets in the field! Thank you for the continued support!

Main_Class.Java
	public class Main_Class {
		public static void main(String[] args) {
			
			String result;
			int number1, number2;
			String msg;
			ProgramDisplay pd = new ProgramDisplay();
			UserInput ui = new UserInput();
			InputValidation iv = new InputValidation();
			NumberOperations no = new NumberOperations();
			number1 = ui.getFirstNumber();
			number2 = ui.getSecondNumber();
			// start of infinite loop
			while (true)
			{
			number1 = ui.getFirstNumber();
			number2 = ui.getSecondNumber();

			no.setNumber1(number1);
			no.setNumber2(number2);

			msg = no.calcSum(number1, number2);
			msg += no.calcDiff(number1, number2);
			msg += no.calcProduct(number1, number2);
			msg += no.calcAvg(number1, number2);
			msg += no.determineAbsVal(number1, number2);
			msg += no.determineMax(number1, number2);
			msg += no.determineMin(number1, number2);

			if (iv.validateInput100()
			msg += no.determineNumOv100();

			if (iv.validateInputNegNum())
			msg += no.determineNegNums();

			pd.displayResult(msg);

			pd.endQstn();

			}//End infinite loop
			}//End method
		} //End class 


InputValidation.Java
Warning: The static method displayResult(String) from the type ProgramDisplay should be accessed in a static way x2 of this warning.
Compiler Error: This method must return a result of type Boolean ( I need to add a return statement yet I dont believe I need to do anythign WITH the value returned other than a Dialog box stating over or under specified value.
public class InputValidation {
	public Boolean validateInput100() {
		NumberOperations NumOp = new NumberOperations();
		ProgramDisplay pd = new ProgramDisplay();
		if (NumOp.getNumber1() > 100 && NumOp.getNumber2() > 100)
			{
				NumOp.setNumber1(NumOp.getNumber1() - 100);
				NumOp.setNumber2(NumOp.getNumber2() - 100);
				pd.displayResult("Both numbers were > 100, so now they are " + NumOp.getNumber1() + " and " + NumOp.getNumber2() + " respectively");
			}
			else
				pd.displayResult("Both numbers are not > 100");
		//OK, now you have to write the code for negative numbers
			
	}
	public void validateInput0() {
		NumberOperations NumOp = new NumberOperations();
		ProgramDisplay pd = new ProgramDisplay();
		if (NumOp.getNumber1() < 0 && NumOp.getNumber2() < 0)
			{
				NumOp.setNumber1(NumOp.getNumber1() + 200);
				NumOp.setNumber2(NumOp.getNumber2() + 200);
				pd.displayResult("Both numbers were < 0, so now they are " + NumOp.getNumber1() + " and " + NumOp.getNumber2() + " respectively");
			}
			else
				pd.displayResult("Both numbers are < 0");
			
	}
}



NumberOperations.Java
public class NumberOperations {
	static int number1;
	static int number2;

	public void setNumber1(int num){
		number1 = num;
	}
	
	public void setNumber2(int num){
		number2 = num;
	}
	
	public int getNumber1(){
		return number1;
	}

	public int getNumber2(){
		return number2;
	}

	public String calcSum(int number1, int number2)
	{   int sum;
		String result;
		sum =  number1 + number2;
		//Note the complete formatting for the output
		result = number1 + " + " + number2 + "=" + sum;
		return result;
	}
	
	public String calcDiff(int number1, int number2)
	{   double diff;
		String result;
		diff =  number1 / number2;
		//Note the complete formatting for the output
		result = number1 + " / " + number2 + "=" + diff;
		return result;
	}
	
	public String calcAvg(int number1, int number2)
	{   double Avg;
		String result;
		Avg =  (number1 + number2)/2.0;
		result = "(" + number1 + "+" + number2 + ")" + "/2.0" + "=" + Avg;
		return result;
	}
	
	public String calcProduct(int number1, int number2)
	{   int Product;
		String result;
		Product =  number1 * number2;
		result = number1 + " x " + number2 + "=" + Product;
		return result;
	}
	
	public String determineMin(int number1, int number2)
	{   
		String result;
		int min;
		if (number1 > number2)
			min = number2;
		else
			min = number1;
		//The above 5 lines could be replaced with the following line
		//int min = (number1 > number2) ? number2 : number1;
		result = "The minimum is: " + min;
		return result;
	}

	public String determineMax(int number1, int number2)
	{   
		String result;
		int max;
		if (number1 < number2)
			max = number2;
		else
			max = number1;
		result = "The maximum is: " + max;
		return result;
	}
	
	public static boolean determineOver100(int number1, int number2)
	{   
		if (number1 > 100 && number2 > 100)
			return true;
		else
			return false;
		//The above  lines could be replaced with the following line
		//return (number1 > 100 && number2 > 100) ? true : false;
	}
	
	public static boolean determineUnder0(int number1, int number2)
	{   
		if (number1 < 0 && number2 < 0)
			return true;
		else
			return false;
		//The above  lines could be replaced with the following line
		//return (number1 < 0 && number2 < 0) ? true : false;
	}
	
}



ProgramDisplay.java
import javax.swing.JOptionPane;


public class ProgramDisplay {
	public static void  DisplayInstructions()
	{
		JOptionPane.showMessageDialog(null,"Enter Numbers\nPress Ok After Each\nView Results", "Instructions", JOptionPane.INFORMATION_MESSAGE);
		JOptionPane.showMessageDialog(null,"Created By: Brandon Berne\nClass: CiS247\nDate: 11/18/09", "About", JOptionPane.INFORMATION_MESSAGE);
	}
	public static void displayResult(String msg)
	{
		JOptionPane.showMessageDialog(null,msg,"Results",JOptionPane.PLAIN_MESSAGE);
	}
}



UserInput.Java
import javax.swing.JOptionPane;

	public class UserInput {
		public int getFirstNumber()
		{
			String strNum;
			int num;
			strNum = JOptionPane.showInputDialog("Enter first integer");
			num = Integer.parseInt(strNum);
			return num;
		}
		public int getSecondNumber()
		{
			String strNum;
			int num;
			strNum = JOptionPane.showInputDialog("Enter second integer");
			num = Integer.parseInt(strNum);
			return num;
		}
		public int getSecondNumber() {
			// TODO Auto-generated method stub
			return 0;
		}
	}

Was This Post Helpful? 0
  • +
  • -

#11 Sollek  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 28-July 09

Re: Learning Objects and Classes

Posted 21 November 2009 - 07:54 PM

Week4 Revised Still a few questions some of which posted above.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1