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 impedance mismatch problem? Which of the three programming
kykrilka [37]

Answer:

The problem that created due to the difference in the model of programming language and the database model.

Explanation:

The practical relational model has three components which are as follows

1. Attributes

2. Datatypes

3. Tuples

To minimize this problem  

1. We switch low pass L-Network to high pass L-network

2. We switch high pass L-Network to low pass L-network

3. We use the impedence matching transformer

3 0
3 years ago
Explain in details three security countermeasures you know.​
SpyIntel [72]

Answer:

The three options are:

1. Avoid sharing files and folders over the network without the permission of your administrators. You might fall in trouble otherwise.

2. Never share your credit card details with a third party through the internet. You can lose a lot of or all your money.

3. Always ensure that your password is strong enough or else your account can be hacked, And never share them with anybody.

Explanation:

Please check the answer.

4 0
3 years ago
Which two keys on the keyboard allow an access user to move the insertion point to the next field to the right in datasheet view
Mashcka [7]
Hey there!

In Microsoft Access, you can click the Tab key then the Enter key on your keyboard to establish a new insertion point directly to the right of your current insertion point when entering data in datasheet view. 

Hope this helped you out! :-)
4 0
3 years ago
To display the size of your backup file, you can use the Windows program called: Windows Explorer Scan disk Defrag Windows Acces
Nitella [24]
Windows Explorer scan disk
7 0
2 years ago
How many assignments would you have failed without brainly?<br><br> lol.
svetoff [14.1K]
How many assignments would I have failed without brainy? Lol

ALL OF THEM
7 0
3 years ago
Other questions:
  • A url consists of a ____, a domain name, sometimes the path to a specific web page or location in a web page, and the web page n
    11·1 answer
  • Websites that are designed to adapt gracefully to any screen size use a technique called
    5·1 answer
  • What component of effective feedback is demonstrated by giving examples of what an employee is doing right instead of just prais
    14·2 answers
  • Malcolm is part of a team developing a new smartphone app to track traffic patterns. Because team members are located throughout
    12·1 answer
  • When Mark’s organization implemented an IS, they faced the lack of confidence in users. Which strategy can improve user confiden
    11·1 answer
  • In an AND truth table.
    7·1 answer
  • Your disaster recovery plan calls for tape backups stored at a different location. The location is a safe deposit box at the loc
    13·1 answer
  • Which feature is not in ms PowerPoint​
    12·1 answer
  • What does it mean when someone says your voice doesn’t match how u look
    7·1 answer
  • Create a timeline of the evolution of computers and their impact on society
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!