Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A Class with Member Variables (Instance Variables) and Methods In this assignmen

ID: 3712089 • Letter: A

Question

A Class with Member Variables (Instance Variables) and Methods

In this assignment you will implement a Java class definition containing member variables (also known as “instance variables,” or “fields”) and methods. You are not implementing a Java program, and your class definition should not have a “public static void main()” method.

Your class needs to have eight member variables, and it needs to have one member variable for each primitive type in the Java language. The eight primitive types in Java are: int, double, boolean, char, byte, short, long, and float. Your class should declare one member variable of each of these eight types. You may declare the variables in any order you like, and name the variables whatever you like, but remember that your class will not compile if your variable name is not a valid Java identifier, and it will not compile if a variable is declared to have the same name as another variable. See BPwJfD Listing 17-2 (pg 335) for an example of how to declare classes with instance variables. You do not need to use modifiers like “public”, “private” or “static” on any of these member variables.

Your class also needs to have two methods:

One method must be named “foo”. Your foo method must have a return value type of “void”, and must have one parameter/argument of type double.

The second method must be named “bar”. Your “bar” method must have a return value type of char, and must take no parameters/arguments.

You are not required to put any functionality inside either of these methods, except for a “return” statement, which is required for “bar” because it returns a value of type “char”. You may implement “bar” to return any char value that you like. You do not need to use modifiers like “public”, “private” or “static” on these methods.

Your class should be called MembersOnly, and it should be in a file called MembersOnly.java. We suggest that you make sure that your MembersOnly class can compile by creating it in Eclipse using File->New->Class, and making sure that there are no red x’s in the code panel when you save it. You won’t be able to run this class as a program, because it won’t have a “public static void main()”.

Explanation / Answer

Please find the code below withd detailed inline comments.

CODE

==================

public class MembersOnly {

   int a;

   double b;

   boolean c;

   char d;

   byte e;

   short f;

   long g;

   float h;

  

   void foo(double d) {

       return;

   }

  

   char bar() {

       return ';';

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote