I am a Grade 11 Computer Science Student, and I am struggling with my work. I do not understand most of the things being taught in this class, and it doesn't help that I didn't take the Grade 10 Course.
The reason for my not understanding lies in that I didn't pay much attention in class. I'm in a tough situation right now, and I would really appreciate help with my homework. Rather than just getting the answers to the questions, I would also like to know WHAT I had to do and WHY. Sorry if I seem pushy, that's not how I'm trying to reach you guys, I'm just an idiot in need of some assistance.
I have received an assignment involving methods, and I don't know how to do it. I will post the assignment and all of its details below, and I would really appreciate it if someone could answer the questions for me and tell me what they did and how I should do it. Please try to keep instructions simple, I don't have a very good knowledge of the workings of Java.
I thank you all for your assistance.
INSTRUCTIONS (The code we are working with is located below)
1. Convert findMax() into a method that returns the maximum integer. Remember to get rid of the static class variable.
2. Get rid of the i1 variable in the getInteger() method by returning the result of parseInt().
3. Make a call to your findMax() method which will calculate the maximum of 3 integers. Do not change your findMax() method to accomplish this, think about how to call your function with 3 values.
4. Create a new function to add two integers together returning the sum back to us. Use your new addition method to add two integers and then 4 integers. Print your answers out in a nicely formatted output.
CODE WE ARE WORKING WITH
The reason for my not understanding lies in that I didn't pay much attention in class. I'm in a tough situation right now, and I would really appreciate help with my homework. Rather than just getting the answers to the questions, I would also like to know WHAT I had to do and WHY. Sorry if I seem pushy, that's not how I'm trying to reach you guys, I'm just an idiot in need of some assistance.
I have received an assignment involving methods, and I don't know how to do it. I will post the assignment and all of its details below, and I would really appreciate it if someone could answer the questions for me and tell me what they did and how I should do it. Please try to keep instructions simple, I don't have a very good knowledge of the workings of Java.
I thank you all for your assistance.
INSTRUCTIONS (The code we are working with is located below)
1. Convert findMax() into a method that returns the maximum integer. Remember to get rid of the static class variable.
2. Get rid of the i1 variable in the getInteger() method by returning the result of parseInt().
3. Make a call to your findMax() method which will calculate the maximum of 3 integers. Do not change your findMax() method to accomplish this, think about how to call your function with 3 values.
4. Create a new function to add two integers together returning the sum back to us. Use your new addition method to add two integers and then 4 integers. Print your answers out in a nicely formatted output.
CODE WE ARE WORKING WITH
Code:
import javax.swing.JOptionPane;
public class PrintMaxNumber3
{
// the fields that belong to the entire class/object are listed next
static int iMaxNum;
// the behaviours that my object can have are listed below (3 of them)
public static int getInteger()
{
int i1;
String strInteger = " ";
strInteger = JOptionPane.showInputDialog("Type in the integer value.");
i1 = Integer.parseInt(strInteger);
return i1;
}
public static void findMax(int num1, int num2)
{
if (num1 > num2)
iMaxNum = num1;
else
iMaxNum = num2;
}
public static void main(String[] args)
{
int iNum1, iNum2;
iNum1 = getInteger();
iNum2 = getInteger();
findMax(iNum1, iNum2);
JOptionPane.showMessageDialog( null,
iMaxNum+" is the larger of "+iNum1+" and "+iNum2,"Maximum Number",
JOptionPane.PLAIN_MESSAGE);
}
}
Last edited: