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 are four differences between tablets and smartphones?
Oksi-84 [34.3K]

Answer:

1. tablets are less portable than smartphones

2. smartphones are considered necessities and tablets are considered luxuries

3. smartphones are personal devices; tablets are usually shared

4. Tablets have larger screens for more extensive use of applications as opposed to the smaller, less versatile mobile phone screens.

8 0
2 years ago
Read 2 more answers
If you use your smartphone as a hotspot to connect to the Internet on your tablet you are using a ________.quillet
Nataly [62]
Personal Area Network
7 0
2 years ago
Explain how the CPU processes data instructions.
Black_prince [1.1K]

Answer:

The actual mathematical operation for each instruction is performed by a combinational logic circuit within the CPU's processor known as the arithmetic logic unit or ALU.

Explanation:

6 0
2 years ago
Ses
jekas [21]

Answer:

Amoung us

Explanation:

When the imposter is sus

8 0
3 years ago
A. Requiring computer users to log off before leaving for lunch
GuDViN [60]

Answer:

Option A, B, and D.

Explanation:

In the above question, the some details of the question are missing that is the part of the question.

Information Security applies to the mechanisms and techniques built and maintained to secure print, computerized, or any other type of personal, secret and confidential information or records from unauthorized access, usage, exploitation, release, damage, manipulation, or disturbance.

So, the following are the option that is true about the scenario.

Other option is not true about the scenario because Option C the click fraud are not the part or protect from the information security and Option F is not considered to the following scenario.

7 0
3 years ago
Other questions:
  • The system administrator in your office quits unexpectedly in the middle of the day. It's quickly apparent that he changed the s
    10·1 answer
  • Assume that
    7·1 answer
  • Which of the following is something that scientists often seek by using computer models and simulations?
    8·2 answers
  • The next generation ip version and successor to ipv4 is called what? ipv5 ipv6 iana ssl
    13·1 answer
  • A user reports that nothing happens when he or she attempts to print from the computer at his desk. This points to a possible pr
    11·2 answers
  • Which is technologically backward country? Options United States U K CHILE INDIA
    14·1 answer
  • Which of the following statements best reflects the pros and cons of overtime potential for a line installer or repairer?
    15·1 answer
  • Read the attached paper titled A Survey of Coarse-Grained Reconfigurable Architecture and comment on it. Make sure to specifical
    5·1 answer
  • Blockquote
    11·1 answer
  • Imagine that you are about to make a presentation during an online meeting, where people will need to be able to see you, and yo
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!