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]
4 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]4 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
The fraction 460/7 is closest to which of the following whole numbers?
Bess [88]
I don’t see any of “the following numbers”
3 0
3 years ago
4) Short answer questions<br>c) What is Cyber Law?​
Kamila [148]

Answer:

Kindly check explanation

Explanation:

Laws refer to legal rules and regulatory framework which is used as a guiding principle to define the actions and behavior which may lead to incurring penalties if boundaries are trespassed.

The word 'Cyber' is popularly used to describe activities, actions and interactions involving the internet. With the burst and continous pace of digital transformation, the internet also called Cyberspace is in a world of its own. Hence, the creation of rules to govern internet interactions.

Cyber laws may thus be explained as codified laws which are designed and implemented to govern all forms of possible online interaction or transactions in other enhance cyber security to protect the interest of persons and data from various forms of internet threats. Cyber laws include ; Data protection laws, Computer crime laws, telecommunication laws and so on.

6 0
3 years ago
Element will you include to present numerical data on the slide
Sveta_85 [38]
I believe a graph, because it shows data.
8 0
4 years ago
Want to network 2 laptops togetger using ethernet cable...But it won't connect
Leona [35]

Make sure both of the laptops are on the same internet, also- find "Network and Sharing Center" in the control panel. If you need more help or a better explanation, make sure to comment.

6 0
3 years ago
in a typical e-mail address, the "host" is A. an account designated by a user name B. CPU processor 2500 C. the receiver of an e
NISA [10]
The correct answer is A! :)
5 0
3 years ago
Read 2 more answers
Other questions:
  • File formats are linked to certain programs.<br><br> True<br> False
    12·2 answers
  • What wired channel, commonly used for cable tv, consists of an insulated copper wire wrapped in a solid or braided shield placed
    12·1 answer
  • How do you change brightness on acer laptop?
    7·1 answer
  • Which of the following are engine features of 2018 TITAN XD Diesel but not of 2018 TITAN XD Gas?
    13·1 answer
  • Sukhi needs to insert a container into her form to collect a particular type of information. Which object should she insert?
    6·1 answer
  • Instructions:Select the correct answer.
    8·2 answers
  • Pleases Help ME An example of a _________________ impact is when a product is back ordered and the business contacts the custome
    5·1 answer
  • How can computational thinking techniques be applied to software development
    6·1 answer
  • Help fast pleas. 3. How is this text formatted? (1 point)
    14·1 answer
  • HELP!!!!!!!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!