Questions
BIG JAVA CH4: Understand the proper use of constants Question: What is the purpose of keyword...

BIG JAVA

CH4: Understand the proper use of constants

Question:

What is the purpose of keyword final? Explain what happens when you use it and give an example.

In: Computer Science

3.1.1 Implement the pop() operation in the stack (1 mark) Implement a stack class named Stack2540Array...

3.1.1 Implement the pop() operation in the stack (1 mark) Implement a stack class named Stack2540Array using array. The starter code is as follows. The instance variables and most operations are provided. You need to implement the pop operation. Make sure that your program checks whether the stack is empty in the pop operation. The implementation can be found in the book and in our lecture slides.

import java . io .*;

import java . util .*;

public class Stack2540Array {

int CAPACITY = 128;

int top ;

String [] stack ;

public Stack2540Array () {

stack = new String [ CAPACITY ]; top = -1; } 1 3.1 Implement the stack ADT using array 3 TASKS public int size () { return top + 1; } public boolean isEmpty () { return ( top == -1) ; } public String top () {

if ( top == -1)

return null ;

return stack [ top ];

}

public void push ( String element ) {

top ++;

stack [ top ] = element ; }

In: Computer Science

Please don't copy and paste from the internet. Thank you - What is meant by term...

Please don't copy and paste from the internet. Thank you

- What is meant by term “inelastic traffic” on a network?

- Explain the primary difference between network applications that use client-server architecture and applications that use peer-to-peer architecture.

- What is meant by the term “peer-churn” with respect to peer-to-peer application architectures?

- Describe in one sentence what is represented by a “port” number to the protocol operating in the transport layer in layered protocol architecture.

Please don't copy and paste from the internet. Thank you

In: Computer Science

JAVA You will then prompt the user to enter each grocery item and store it in...

JAVA

You will then prompt the user to enter each grocery item and store it in your array. Afterward, the program will ask the user to enter which grocery item they are looking for in the list, and return a message back on whether it was found or not found.

(Hint: You will need two for-loops for this program - one for storing each element into the array and one for searching back through the array.) See below for example output:

Example output 1:

How many items would you like on your grocery list?

3

Enter item 1:

potato

Enter item 2:

cheesecake

Enter item 3:

bread

Welcome to your digital grocery list!

What item are you looking for?

bread

bread was found in your list!

Example output 2:

How many items would you like on your grocery list?

3

Enter item 1:

potato

Enter item 2:

cheesecake

Enter item 3:

bread

Welcome to your digital grocery list!

What item are you looking for?

muffins

muffins not found.

In: Computer Science

Develop a program, in which you'll design a class that holds the following personal data: name,...

Develop a program, in which you'll design a class that holds the following personal data: name, address, age, and phone number. As part of the program, you'll then create appropriate accessor and mutator methods. Also, set up three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information.

Input:

  • data for the following attributes of 3 instances of the  Personal Information Class:
  • name, address, age, and phone number

NOTE: The input data do not need to be real data; they need to be entered at the keyboard, when program is run.

Processing: Develop the following:

  • Personal Information Class
  • A program that creates three instances of the above class

Output:

Set up a loop and display data within each object:

  • name, address, age, and phone number

In: Computer Science

Consider a B-tree allowing splits and free-on-empty. Please show an example of these operations on a...

Consider a B-tree allowing splits and free-on-empty. Please show an example of these operations on a data structure containing 15 data items, a fanout of three, and at most three data items per node. Also give the search algorithm (use a give-up scheme).

In: Computer Science

Problem: HugeIntegerClass Create a class HugeInteger which uses a 40-element array of digits to store integers...

Problem: HugeIntegerClass

Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods Input, toString, Add, and Subtract. For comparing HugeInteger objects, provide the following methods: IsEqualTo, IsNotEqualTo, IsGreaterThan, IsLessThan, IsGreaterThanOrEqualTo and IsLessThanOrEqualTo. Each of these is a method that returns true if the relationship holds between the two HugeInteger objects and returns false if the relationship does not hold. Provide method IsZero. In the Input method, use the string method toCharArray to convert the input string into an array of characters, then iterate through these characters to create your HugeInteger. If you feel ambitious, provide methods Multiply, Divide, and Remainder


// Driver Class

Import.java.*;

public class <LastName>_HugeIntegerTest
{
   public static void Main(string[] args)
   {
      HugeInteger integer1 = new HugeInteger();
      HugeInteger integer2 = new HugeInteger();

      System.out.println("Enter first HugeInteger: ");
      integer1.Input(Console.ReadLine());

      System.out.println ("Enter second HugeInteger: ");
      integer2.Input(Console.ReadLine());

      System.out.println ("HugeInteger 1”+ integer1);
      System.out.println ("HugeInteger 2” +integer2);

      HugeInteger result;

      // add two HugeIntegers
      result = integer1.Add(integer2);
      System.out.println ("Add result” + result);

      // subtract two HugeIntegers
      result = integer1.Subtract(integer2);
      System.out.println ("Subtract result” + result);

      // compare two HugeIntegers
      System.out.println ( "HugeInteger 1 is zero: “ + integer1.IsZero());
      System.out.println ( "HugeInteger 2 is zero: “ + integer2.IsZero());
      System.out.println (
         "HugeInteger 1 is equal to HugeInteger 2: “ + integer1.IsEqualTo(integer2));
      System.out.println (
         "HugeInteger 1 is not equal to HugeInteger 2:” + integer1.IsNotEqualTo(integer2));
      System.out.println (
         "HugeInteger 1 is greater than HugeInteger 2: “ + integer1.IsGreaterThan(integer2));
      System.out.println (
         "HugeInteger 1 is less than HugeInteger 2:” + integer1.IsLessThan(integer2));
      System.out.println (
         "HugeInteger 1 is greater than or equal to HugeInteger 2: “ + integer1.IsGreaterThanOrEqualTo(integer2));
      System.out.println ( "HugeInteger 1 is less than or equal to HugeInteger 2: “ + integer1.IsLessThanOrEqualTo(integer2));
   }
}


Sample Run 1:

Enter first HugeInteger:

1234567890123456789012345678901234567890

Enter second HugeInteger:

0987654321098765432109876543210987654321

HugeInteger1 +1234567890123456789012345678901234567890

HugeInteger2 +987654321098765432109876543210987654321

Add result+2222222211222222221122222222112222222211

Subtract result+246913569024691356902469135690246913569

HugeInteger 1 is zero: false

HugeInteger 2 is zero: false

HugeInteger 1 is equal to HugeInteger 2: false

HugeInteger 1 is not equal to HugeInteger 2:true

HugeInteger 1 is greater than HugeInteger 2: true

HugeInteger 1 is less than HugeInteger 2:false

HugeInteger 1 is greater than or equal to HugeInteger 2: true

HugeInteger 1 is less than or equal to HugeInteger 2: false

Sample Run 2:

Enter first HugeInteger:

65479876253763637782636782636

Enter second HugeInteger:

989

HugeInteger1 +65479876253763637782636782636

HugeInteger2 +989

Add result+65479876253763637782636783625

Subtract result+65479876253763637782636781647

HugeInteger 1 is zero: false

HugeInteger 2 is zero: false

HugeInteger 1 is equal to HugeInteger 2: false

HugeInteger 1 is not equal to HugeInteger 2:true

HugeInteger 1 is greater than HugeInteger 2: true

HugeInteger 1 is less than HugeInteger 2:false

HugeInteger 1 is greater than or equal to HugeInteger 2: true

HugeInteger 1 is less than or equal to HugeInteger 2: false

public class HugeInteger

{

private final int DIGITS = 40;

private int[] integer;// array containing the integer

private boolean positive; // whether the integer is positive

// parameterless constructor

public HugeInteger()

{

//

}

// Convert a string to HugeInteger

public void Input(String inputstring)

{

//

}

// add two HugeIntegers

public HugeInteger Add(HugeInteger addValue)

{

//

}

// add two positive HugeIntegers

private HugeInteger AddPositives(HugeInteger addValue)

{

//

}

// subtract two HugeIntegers

public HugeInteger Subtract(HugeInteger subtractValue)

{

//

}

// subtract two positive HugeIntegers

private HugeInteger SubtractPositives(HugeInteger subtractValue)

{

//

}

// find first non-zero position of HugeInteger

private int FindFirstNonZeroPosition()

{

//

}

// get string representation of HugeInteger

public String toString()

{

//

}

// test if two HugeIntegers are equal

public boolean IsEqualTo(HugeInteger compareValue)

{

//

}

// test if two HugeIntegers are not equal

public boolean IsNotEqualTo(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is greater than another

public boolean IsGreaterThan(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is less than another

public boolean IsLessThan(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is greater than or equal to another

public boolean IsGreaterThanOrEqualTo(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is less than or equal to another

public boolean IsLessThanOrEqualTo(HugeInteger compareValue)

{

//

}

// test if one HugeInteger is zero

public boolean IsZero()

{

//

}

//Optional

public HugeInteger multiply(HugeInteger multiplyValue)

{

//

}

}

In: Computer Science

Please Use your keyboard (Don't use handwriting) Thank you.. I need new and unique answers, please....

Please Use your keyboard (Don't use handwriting) Thank you..

I need new and unique answers, please. (Use your own words, don't copy and paste)

Q1:

Your team is asked to program a self-driving car that reaches its destination with minimum travel time.

Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are given.

Q2:

Write a complete Java program that prints out the following information:

  1. Declare String object and a variable to store your name and ID.
  2. DisplayYour Name and Student ID.
  3. Display Course Name, Code and CRN
  4. Replace your first name with your mother / father name.
  5. Display it in uppercase letter.

Note:Your program output should look as shown below.

My Name: Ameera Asiri

My student ID: 123456789

My Course Name: Computer Programming

My Course Code: CS140

My Course CRN: 12345

AIYSHA ASIRI

Note : Include the screenshot of the program output as a part of your answer.

_____

Q3:

Write a tester program to test the given class definition.

Create the class named with your id with the main method.

  1. Create two mobiles M1 and M2 using the first constructor.
  2. Print the characteristics of M1 and M2.
  3. Create one mobile M3 using the second constructor.
  4. Change the id and brand of the mobile M3. Print the id of M3.

Your answer should be supported with the screenshot of the output, else zero marks will be awarded.

public class Mobile

{

int id;

String brand;

public Mobile()

{

id = 0;

brand="";

}

public Mobile(int n, String name)

{

id = n;

brand=name;

}

          public void setBrand(String w)

          {

               brand = w;

           }

          public void setId(int w)

          {

                 id = w;

           }   

         public int getId()

          {

             return id;

            }

          public String getBrand()

         {

               return brand;

          }

}

___

Q4:

Write a method named raiseSalary that accepts two integers as an argument and return its sum multiplied by 15%. Write a tester program to test the method. The class name should be your ID.

Your answer should be supported with a screenshot of the program with output.

In: Computer Science

Consider f,g:ℤ→ℤ given by: f(n) = 2n g(n) = n div 2 Which of the following...

Consider f,g:ℤ→ℤ given by:

  • f(n) = 2n
  • g(n) = n div 2

Which of the following statements are true? Select all that apply

(a)

f is an injection

(b)

g is an injection

(c)

f∘g is an injection

(d)

g∘f is an injection

(e)

f is a surjection

(f)

g is a surjection

(g)

f∘g is a surjection

(h)

g∘f is a surjection

In: Computer Science

1. Provide brief answers to the following questions: a) What is preprocessing in C programming language?...

1. Provide brief answers to the following questions:
a) What is preprocessing in C programming language? Cite 3 examples of preprocessor directives in C.
b) What is the main difference between Heap and Stack memory regions?
c) What is the difference between Stack and Queue?
d) What is the purpose of a compiler? Name the C compiler that you used for this course?
e) What is a pointer variable in C?

2. int var;
Use this variable to write a single line code in C to read input using scanf library function call.

In: Computer Science

Using SET operations, display a list of customers that are interested in a car (prospect table)...

Using SET operations, display a list of customers that are interested in a car (prospect table) of the same make and model which they already own.

In: Computer Science

Which command do you use to find the process that’s holding a file open? 1. w...

Which command do you use to find the process that’s holding a file open?

1.

w

2.

ps

3.

top

4.

fuser

In: Computer Science

As a second example, consider the communication paradigm referred to as queued RPC, as introduced in...

As a second example, consider the communication paradigm referred to as queued RPC, as introduced in Rover [Joseph et al. 1997]. Rover is a toolkit to support distributed systems programming in mobile environments where participants in communication may become disconnected for periods of time. The system offers the RPC paradigm and hence calls are directed towards a given server (clearly space-coupled). The calls, though, are routed through an intermediary, a queue at the sending side, and are maintained in the queue until the receiver is available. To what extent is this time- uncoupled? Hint: consider the almost philosophical question of whether a recipient that is temporarily unavailable exists at that point in time.

In: Computer Science

why are direct input and outputs highly discouraged in setters and getters

why are direct input and outputs highly discouraged in setters and getters

In: Computer Science

9. #include <fstream> #include <iostream> using namespace std; int main() {     float bmi;     ifstream...

9. #include <fstream>
#include <iostream>
using namespace std;

int main()
{
    float bmi;
    ifstream inFile;
    inFile.open("bmi.txt");

    while (!inFile.eof())
      {
         inFile >> bmi;
         if( bmi < 18.5)
          {
              cout << bmi << " is underweight " ;
          }
        else if( bmi >= 18.5 && bmi <= 24.9)
          {
              cout << bmi << " is in normal range " ;
          }
        else if( bmi >= 25.0 && bmi <= 29.9)
          {
              cout << bmi << " is overweight " ;
          }
        else if( bmi >= 30)
          {
              cout << bmi << " is obese " ;
          }
        cout << endl;
     }
   return 0;
}

bmi.txt looks like below:

25.0

17.3

23.1

37.0

What will be the output when the above code runs with the above bmi.txt file.

In: Computer Science