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
Subscript numbering always starts at what value?
Leni [432]
It always starts with 0
4 0
3 years ago
________ can be written only once. The data cannot be erased or written over once it is saved.​
notka56 [123]

Answer:

WORM (Write Once, Read Many)

Explanation:

The full meaning which means Write Once, Read Many implies that data can only be entered (or better put, written) once. Once the data has been written, the data can not be updated or deleted. However, the data being stored on WORM can be read as many times, as possible.

Hence, WORM answers the question.

6 0
3 years ago
Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
attashe74 [19]

Answer:

Let me see the picture clearly

Explanation:

5 0
4 years ago
Which is the last step in conducting a URL search?
dimulka [17.4K]
The user's browser renders the html code as a visual web page
3 0
4 years ago
Windows organises information on computer using a
zhuklara [117]
The correct answer is b folder
6 0
3 years ago
Read 2 more answers
Other questions:
  • Helllllp: Virtual private networks require a secure remote connection.<br> True or False?
    10·2 answers
  • You notice that lately your computer has been running slow. When you open up your web browser, you get endless pop-up ads to the
    8·1 answer
  • A form of Internet identity theft involving phony e-mail messages asking customers to update their credit card numbers, account
    7·1 answer
  • What is f(-3) for the function f(a)=-2a2-5a+4?​
    10·1 answer
  • What is the purpose of the .NET Framework Class Library? a. it provides pre-written code that can be used by .NET applications b
    13·1 answer
  • What is wrong with each of the following?
    6·1 answer
  • Answer the following questions: • What is the source of the user’s request? Can a technical solution solve his problem? Perhaps
    10·1 answer
  • discuss the benefits of normalization, and do you think we should normalize our designs to higher levels than 3NF? Why or why no
    9·1 answer
  • What are acenders? What are decenders?
    10·2 answers
  • Most effective way of closing email is<br>​
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!