I have a homework assignment that's due in a couple of days and I need a set of experienced Java eyes to confirm that a few of the answers to the questions below are correct. The hard part about these questions (for me anyways as a newbie Java person) is that each question is dependent on the previous question, so if the first parts aren't right, then the answers following prob won't be either. Any help or guidance you can provided would be GREATLY appreciated!!!
Question 1
Create a public Class called Q4. Include two member variables (an int and a float). Add a method to Q4 called printValues() that prints the values of the two member variables. (Hint: The correct answer will not have a Main method)
ANSWER
public class Q4 {
//MEMBER VARIABLES
int integer1;
float float1;
public void printValues() {
System.out.println("integer1, float1");
}
}
Question 2
Show a constructor for the Q4 class in Question 1. It must take two parameters that set some initial values for the member variables.
ANSWER
public class Q4 {
public Q4(int integer1, float float1) {
this.integer1 = integer1;
this.float1 = float1;
}
//MEMBER VARIABLES
int integer1;
float float1;
public void printValues() {
System.out.println("integer1, float1");
}
}
Question 3
Create a separate class called UseQ4 that instantiates the Q4 class from Question 1 using the constructor from Question 2. (Hint: The correct answer on this one will have a Main method)
ANSWER
Q4 myInstanceOfQ4(3,5.5);
float mytotal;
mytotal = myInstanceOfQ4.add_values();
Question 4
Add a line to UseQ4 from Question 3 that calls printValues() to display the values of Q4’s member variables.
ANSWER
myInstanceOfQ4.print_values();
Again, any help or guidance you can provided would be GREATLY appreciated!!! Thx.