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
Answer for 3.4.8 rectangle code HS
tigry1 [53]

Answer:

i think Make variables to represent the length and width of a rectangle, called length

and width

, respectively. You should set length

to 10 and width

to 5.

Then, write some mathematical expressions to computer the area and perimeter of the rectangle and save these values inside variables named area and perimeter

.Use print

statements to display the area and perimeter of the rectangle.

Your output should print the area on the first line and the perimeter on the second, like this:

50 30  Rectangle Area Formula:

Area = L * W

Explanation:

7 0
2 years ago
Question 12 (1 point)
QveST [7]

Answer:

margins

Explanation:

the definition margins are the edges

8 0
3 years ago
The domain in an email message tells you the
Alexus [3.1K]
The type of service provider
8 0
3 years ago
Tfuuvj vjiibjoon Ghosh kpj
Nookie1986 [14]

Answer: A

Explanation: For any formal document you need your major points.

5 0
2 years ago
Read 2 more answers
Notice that the percentages range from just over 55% to just under 65%. This is a range of 10%, so we're going to use 5 evenly-s
vfiekz [6]

Answer:

import numpy as np

l_int = 55/100

h_int = 65/100

hist = np.histogram( paid_tax_preparers_list, bins=5, range=(l_int, h_int))

Explanation:

Numpy is a Python package used to ease mathematical and statistical research calculations. The package creates data structures called arrays that can be used as vector items, making it easy and fast for calculation to be done.

The np.histogram method is used to create or plot histograms of a list or array against the frequency of the items in the array. The bins and the range attributes are used to adjust the display of the histogram, with bins being the number of bin in the graph and range is the given length of the histogram.

7 0
2 years ago
Other questions:
  • Which of the following is not a typical step in the ethical hacking process? A. Planning B. Discovery C. Attack D. Recovery
    5·1 answer
  • What is the difference between deta security and privecy ?
    12·2 answers
  • Which relationship is possible when two tables share the same primary key? one-to-one one-to-many many-to-one many-to-many
    15·2 answers
  • . Two or more functions may have the same name, as long as their _________ are different.
    9·1 answer
  • List and describe the tools for all the main stages of app/application development.
    11·1 answer
  • What is information technology
    11·1 answer
  • What term refers to the text label that describes each data series?
    9·1 answer
  • Gta! ! ! !!aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    11·2 answers
  • What statement describes the last step in evaluating<br> information?
    10·1 answer
  • You are the administrator for the ABC Company. You are looking to install Windows Server 2016, and you need to decide which vers
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!