package learning;
public class LargeInt {
int array[];
boolean sign;
int size;
LargeInt(){
array = new int[5]; // Initial Size set to 5
sign = true; // true means
positive and false means negative
}
LargeInt(int num){
setNumber(num);
}
/****
*
* This function takes the number which need to be stored . Set the
sign . true means positive ,false means negative.
* Count the nuber of digits in the input number. Makes the Size of
the array which can store those digits. and stores the number in
the array
* in forward direction.
* @param num
*/
public void setNumber(int num){
if(num < 0){
sign = false;
}else{
sign = true;
}
int count = countDigits(num);
size = count;
System.out.println("count " + count);
while(array.length < count){
array = increaseArraySize(array);
}
while(num != 0){
System.out.println(num%10);
array[count-1] = num %10;
num = num /10;
count = count -1;
}
}
/****
* THis function is used to count the digits in the number
* @param num
* @return
*/
public int countDigits(int num){
int count = 0;
while(num != 0){
num = num/10;
count++;
}
return count;
}
/****
* This function dynamically doubles the array Size
* @param arr
* @return
*/
public int [] increaseArraySize(int [] arr){
int [] brr = new int[(arr.length *2)];
for(int i=0; i<arr.length; i++){
brr[i] = arr[i];
}
return brr;
}
public String toString(){
StringBuilder sb = new StringBuilder();
if(sign){
sb.append("+ ");
}else{
sb.append("- ");
}
for( int i =0 ; i<size; i++){
sb.append(array[i]);
}
return sb.toString();
}
public static void main(String args[]){
LargeInt largeInt = new LargeInt();
largeInt.setNumber(123456789);
System.out.println(largeInt);
}
}
MAKE SURE TO INCLUDE WHAT PORTION OF THE CODE GOES IN WHAT FILE FOR THE CLASS....
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...
Suppose that you write a new class. If you do not specifically write a constructor for the class, the compiler will provide one by default: TRUE FALSE Suppose that you what to iterate through each data element of an array. What control statement would best accomplish this task: If-then-else For Switch Do-while Which of the following is the best method to destroy an object that is currently on the heap: Set the reference variable of the object to NULL Disable...
C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...
Implement the following: a. A template class named MyArray. 1) MyArray is a dynamic partially filled array for primitive types. 2) data members: - a pointer for the array - any associated variables needed to manage the array. 3) Constructor must insure that specified capacity is possible. Exit the program if an illegal value is specified. 4) “The Big Three” are required to insure deep copy. 5) Private grow function is used to automatically increase the size of the array...
1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When you look at a constructor, how can you determine if it is THE default constructor? 3. What can a “friend” function do that other non-member functions can not do? 4. class plane { int x;} ---------------- is x public or private? 5. What kind of a search first sorts the data into ascending or descending order, then splits the data in half, searches, splits,...
Write C++ program T 1030 UUIII DUCOUL The bar code on an envelope used by the US Postal Service represents a five (or more) digit zip code using a format called POSTNET (this format is being deprecated in favor of a new system, OneCode, in 2009). The bar code consists of long and short bars as shown below: Illlllllllll For this program we will represent the bar code as a string of digits. The digit 1 represents a long bar...
PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...
The code snippet below is an example of pass by reference. We also provide a sample method setZeroAt, which sets 0 at a position i in the array, to illustrate pass by reference. public class Sample { public static void setZeroAt(int [] arr, int i){ arr[i] = 0; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int sample[] = {1, 2, 3}; setZeroAt(sample, 1); //Now sample looks like {1, 0, 3} } } Write a Java...
This is programming project 1 chapter 9(Book ISBN:1292222824 (1-292-22282-4) Walter Savitch Problem Solving with C++: Global Edition, 10/E) Question Do Programming Project 7 in Chapter 7 using a dynamic array. In this version of the problem, use dynamic arrays to store the ditits in each large integer. Allow an arbitrary number of digits instead of capping the number of digits at 20. TER 7/ Arrays time. For example digit at a the integer 1234 could be stored in the array...
Please answer the following questions 1. What keyword is used to make a child class use a parent class? a.) is a b.) extends c.) has a d.) inherits 2. Suppose you have the given code below. Scanner keyboard = new Scanner(System.in); What would be the correct way to scan in an integer value from the keyboard. a.) scan.nextInt() b.) scan.nextDouble() c.) scan.nextLine() d.) keyboard.nextInt() 3. True or False. Arrays use sequential blocks of memory while linked lists do not...