1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
max2010maxim [7]
3 years ago
13

Graded Discussion: a. Create your own Unique Java Class Previous Next Provide Java code for a simple class of your choice.b. Be

sure to include at least one constructor, two methods and two fields.c. The fields should be private. d. Create a test class to constuct and call the methods of your class.e. Describe your class and demonstrate your code functions properly.f. Respond to other student postings by testing their Unique classes.
Computers and Technology
1 answer:
alexdok [17]3 years ago
6 0

Answer:

The java program for the given scenario is shown below.

import java.util.*;

import java.lang.*;

class YourClass

{

   // two private integer variables are declared

   private int num1, num2;

   

// constructor has the same name as the class itself

// constructor is similar to a method

// constructor has no return type

// constructor may or may not accept parameters

   YourClass()

   {

       num1 = 1;

       num2 = 2;

   }

       

   // first method

   void add()

   {

      System.out.println("Sum of the numbers " + num1 + " and " + num2 + " is " + (num1+num2) );

   }

   // second method

   void subtract()

   {

      System.out.println("Difference between numbers " + num1 + " and " + num2 + " is " + (num1-num2) );  

   }

   

}

public class Test

{

   public static void main(String args[]) {          

         // object of the class, YourClass, is created

// since constructor takes no parameters, no parameters are passed to the object  

         YourClass ob = new YourClass();

         

         // first method called

         ob.add();

         

         // second method called

         ob.subtract();

   }

}

OUTPUT

Sum of the numbers 1 and 2 is 3

Difference between numbers 1 and 2 is -1

Explanation:

1. The class, MyClass, contains two private fields, one constructor and two methods.

2. The fields are integer variables which are initialized in the constructor.

3. In the add() method, both integer variables are added and their sum displayed with System.println() method.

4. In the subtract() method, both integer variables are subtracted and their difference displayed with System.println() method.

5. In the other class, Test, inside the main() method, the object of the class, MyClass, is created.

6. Using the object, both the methods, add() and subtract(), are called inside main().

7. Java is a purely object-oriented language hence all the code is written inside classes.

8. Only the class which has main() method can be declared as public. Other classes are not declared public.

You might be interested in
What is the purpose of the website directory provided by the website host?
Dennis_Churaev [7]

Answer:

mabye A

Explana

.

.

.

6 0
3 years ago
The application layer in the tcp/ip protocol suite is usually considered to be the combination of ________ layers in the osi mod
navik [9.2K]
Application Presentation and Session Layers.
8 0
3 years ago
During data declaration, a name is binded to a memory location, what else can be identify as part of this process?
igomit [66]

data declaration means a variable which contain data value and it can be declared as integer, float, character, double, boolean (data types).

example:

int r;

char name;

float g;

double k= 23.34;

5 0
3 years ago
________ speeds time to insights and enables better data governance by performing data integration and analytic functions inside
Lyrx [107]
<h3><em>↓Answer↓</em></h3>

<u>In-database analytics</u> speeds time to insights and enables better data governance by performing data integration and analytic functions inside the database.

3 0
2 years ago
When entering a function or formula in a cell, which of the first character you must type?
lions [1.4K]
When entering a function or formula in a cell, which of the first character you must type =
3 0
3 years ago
Read 2 more answers
Other questions:
  • Match the steps with the actions that are involved when an internal host with IP address 192.168.10.10 attempts to send a packet
    11·1 answer
  • Which character is used to begin a comment?
    6·1 answer
  • In this activity, you'll decide how a computer (in this case, a smartphone)
    12·1 answer
  • You are a running cable in a new network. You are running a series of cables from the wiring closet to the RJ-45 ports for the c
    6·1 answer
  • JPG is considered a lossy file format. What does this mean?
    15·2 answers
  • कम्प्युटर को पहिलो पुस्ता भनेको के हो?​
    8·2 answers
  • Select the correct answer from each drop-down menu
    7·1 answer
  • GUYS THERE IS A HACKER IN BRAINLY PLEASE DONT PRESS ON THE WEBSITE THEY WILL HACK YOU.
    9·2 answers
  • How can the system administrator give the executive assistant the ability to view, edit, and transfer ownership of all records,
    6·1 answer
  • Create a function that takes an integer array as input and a value and returns a POINTER to the number of times the value appear
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!