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
ICE Princess25 [194]
3 years ago
15

Design a class named largeIntegers such that an object of this class can store an integer of any number of digits. Add operation

s to add, subtract, multiply, and compare integers stored in two objects. Also add constructors to properly initialize objects and functions to set, retrieve, and print the values of objects. Write a program to test your class. g
Computers and Technology
1 answer:
SpyIntel [72]3 years ago
6 0

Answer:

Here the code is given as follows,

Explanation:

Code:

import java.util.Scanner;

//created class named largeintegers

class largeintegers{

   //class can hold a long number

   long number;

   //constructor to set number

  largeintegers(long number){

      this.number=number;

  }

  //getNumber method to get number

  long getNumber(){

      return number;

  }

  //below are some basic operations

  long addition(long num1,long num2){

       return num1+num2;

   }

   long subtract(long num1,long num2){

       return num1-num2;

   }

   long multiply(long num1,long num2){

       return num1*num2;

   }

   boolean compare(long num1,long num2)

   {

       return num1>num2;

   }

  public static void main(String[] args) {

      //declared to long numbers

      long number1,number2;

      //scanner class to take user input

      Scanner sc= new Scanner(System.in);

      //taking input numbers

      System.out.println("Enter a Number ");

      number1=sc.nextLong();

      System.out.println("Enter 2nd Number :");

      number2=sc.nextLong();

      //created two objects

      largeintegers object=new largeintegers(number1);

      largeintegers object2=new largeintegers(number2);

      //displaying two numbers

      System.out.println("Entered Numbers ");

      System.out.println(object.getNumber());

      System.out.println(object2.getNumber());

      //calling basic methods using created objects

      System.out.println("Some Operations on Given two Numbers ");

      System.out.println("Addition:"+object.addition(object.getNumber(), object2.getNumber()));

      System.out.println("Subtraction:"+object.subtract(object.getNumber(), object2.getNumber()));

      System.out.println("Multiplication:"+object.multiply(object.getNumber(), object2.getNumber()));

      System.out.println("Comparison:");

      if(object.compare(object.getNumber(), object2.getNumber())==true)

      {

          System.out.println("First Number is Greater than Second Number ");

      }

      else

      {

          System.out.println("Second Number is Greater than First Number ");

      }

      sc.close();

  }

}

Output:-

You might be interested in
Which action does not happen in each iteration of the repeat loop in the
iren2701 [21]

B. The number of sharks decreases. Explanation: hope it's help i learned about it and you too

7 0
3 years ago
PLEASE HELP ME!!!!
White raven [17]
The answers are D and A
5 0
3 years ago
Read 2 more answers
If a wheel is adjustable to move caster forward is considered which type
Yuki888 [10]

Maybe axle i think so

8 0
4 years ago
If you would like to give another user permissions on your mailbox or to particular folders within your mailbox, which role shou
Viktor [21]

Answer:

Assignee

Explanation:

4 0
3 years ago
Read 2 more answers
A scientist conducted an experiment and discovered that certain plants grow faster when given a particular amount of fertilizer.
belka [17]

the answer is B: Replication, i put validity on e2020 and it was wrong.

3 0
4 years ago
Read 2 more answers
Other questions:
  • 1. Reference initials are always typed on a business letter.
    6·1 answer
  • Create a class Str that subclasses str. Add a method to the subclass that checks if the string does not start with a given strin
    15·1 answer
  • Which of the following is an acrostic
    13·1 answer
  • Which one of the following analog VOM ranges would be selected to measure a DC
    13·1 answer
  • Which sentence best describes the executive branches of state
    12·1 answer
  • Which of the following rights is NOT guaranteed by copyright?
    11·1 answer
  • PI
    12·1 answer
  • What's the function of a cyclebin​
    14·1 answer
  • Which of the following are pointers?
    9·1 answer
  • Draw the following diagrams to represent the information system chosen in assignment 1 Context diagram The context diagram is ex
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!