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
A security technician is configuring a new firewall appliance for a production environment. The firewall must support secure web
Zielflug [23.3K]

Answer:

Explanation:

Based on the information provided in the question, the best rules that the technician should add to the firewall would be the following

Permit 10.10.10.0/24 0.0.0.0 -p tcp --dport 443

Permit 10.10.10.0/24 192.168.1.15/24 -p udp --dport 53

This is because port 443 is used for "Secure webs services" while UDP port 53 is used for queries and domain name resolution. Both of which are the main configurations that the security technician needs to obtain.

8 0
3 years ago
Can someone please do a java computer science program for me? I’m desperate and I did not have enough time to learn the topic. I
vagabundo [1.1K]
Sure, how would you like me to send you the code?
5 0
3 years ago
What are HITs????????
nasty-shy [4]

It is namely an internet made by someone...

8 0
3 years ago
1
Vitek1552 [10]

Answer:

A

Explanation:

.

.stack 4096

ExitProcess PROTO, dwExitCode:DWORD

.data

Sun=0

Mon=1

Tue=2

Wed=3

Thu=4

Fri=5

Sat=6

warray BYTE Sun, Mon, Tue, Wed, Thu, Fri, Sat

INVOKE ExitProcess, 0

7 0
3 years ago
How to convert from base 2 to base 10​
just olya [345]

Answer:

by adding powers(from 0 to where the base 2 number stops) on the base 2 number

7 0
3 years ago
Read 2 more answers
Other questions:
  • Karen has opened a new business and is using Google Display Ads to build awareness of her new products. How does Google Display
    6·1 answer
  • Write the definition of a function max that has three int parameters and returns the largest.
    6·2 answers
  • Which icon is greater in file size? (Show your working)
    8·1 answer
  • Write a function that accepts an integer parameter and returns its integer square root (if it exists). The function should throw
    12·2 answers
  • Oxnard Casualty wants to ensure that their e-mail server has 99.98 percent reliability. They will use several independent server
    14·1 answer
  • As time goes on, technology is likely to _______. A. Increase in complexity b. Decrease in complexity c. Stay at the same comple
    8·1 answer
  • 1. Which of the following is not related to a buffer overflow? A. Static buffer overflow B. Index error C. Canonicalization erro
    10·1 answer
  • Plz can someone tell me the answers ?
    13·2 answers
  • You have this code in your program.
    7·1 answer
  • In honor of Black History Month, write an essay about a black person who has inspired YOU in some way. This person does not have
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!