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
Who can help me please? ​
malfutka [58]

Answer:

what do you need help with

4 0
2 years ago
​Five elements that can prove the genuineness of a user. What you know, what you have, what you are, what you do, and where you
nataly862011 [7]

Authentication factors are the factors that describe about the ingenuition or origination of the user. This is the tag that tells about the actuality of user that is getting connected with internet by the five elementals.

Hope this helps!

8 0
2 years ago
Which is the best description of a computer virus?
MatroZZZ [7]
The best description of a computer virus is. Someone first starts out making a malicious program, then can send it to a unexpected user. After that, when the user opens the malicious program, it can do negative things on the target. The virus first starts out in the system32, then infects a random file type for example, exe files, or dlls etc. Then random errors can pop up on the computer saying "YOUR COMPUTER IS UNDER RISK! CALL THIS NUMBER NOW! 555-555-5555" and the options of the error, can direct you to a website, that can give you another virus. To get rid of a virus, you have to ignore the popups that comes onto your computer, and get a strong antivirus like avast, or avg. Then let it scan the system. After when the scan is done, it will show up the virus, and it will give you options "to delete virus or ignore it" you would hit delete. I hope this answer helped you. Let me know if you have any more questions! Thanks!
6 0
2 years ago
Read 2 more answers
When installing a SATA hard drive, is it true or false that you need to move the jumpers on the back of the drive to instruct th
antiseptic1488 [7]

Answer:

This is false.

Explanation:

SATA drives do not have jumpers, because they don't use the master/slave feature. They are connected to the motherboard, and they are ready to work.

The master/slave feature was used by IDE hard drives.15 years ago, most motherboards didn't have too many IDE slots to place more than 1 or 2 HDDs, the IDE cable allowed you to connect 2 drives to 1 cable, greatly increasing your computer's storage space.

It was recommended to set as master the drive connected directly to the motherboard, and the other one as slave.

7 0
2 years ago
An ecommerce ____________ is the software that handles ecommerce transactions.​
Shkiper50 [21]
<span>An ecommerce application is the software that handles ecommerce transactions.​  It helps customers to find products, make a selection and submit payment.  A key component of an ecommerce application is an online shopping cart. </span>
7 0
2 years ago
Other questions:
  • The conventional wisdom concerning the security frameworks of domains is that it is always preferable for an organization to cre
    7·1 answer
  • EASY AND I GIVE BRAINLIEST!!! What is a good jeopardy question about operating systems?
    6·1 answer
  • Which question best addresses the issue of risk with a new job?
    7·2 answers
  • Due to the difficult economic times, increased global competition, demand for customization, and increased consumer sophisticati
    9·1 answer
  • How do professionals address their problems?
    14·2 answers
  • Your task is to implement a function replace_once(t, d), that takes a text t and a replacement dictionary d, and returns the res
    10·1 answer
  • The term Linux Intrusion Detection System ( LIDS) refers to a command that allows an administrator to run processes as root with
    5·1 answer
  • How can I download music and films at home without breaking the law?
    11·2 answers
  • My messaging system is messed up. It keeps saying I'm getting messages but then it says nothing new in my inbox. I'm confused- H
    15·2 answers
  • Transaction processing systems (TPSs) provide valuable input to management information systems, decision support systems, and kn
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!