IN JAVA PROGRAMMING
Write a complete Java program to do the following:
a) Prompt the user to enter a six-digit integer.
b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits).
c) Display each 3-digit piece on a separate line with a proper message before each piece.
For example, if the user enters 450835 as the integer, then the program should display the following output:
Right 3-digit piece: 835
Left 3-digit piece: 450
In: Computer Science
Discuss how the OSI model has been able to allow different technologies to communicate over the years. Mention at least two specific networking technology that did not exist 40 years ago that is currently used today, such as e-mail.
In: Computer Science
List three jobs in which working from home is infeasible. Explain why remote work doesn’t work for everyone.
In: Computer Science
in software engineering what are the domain requirements for a museum ?
In: Computer Science
(a) Explain five (5) reasons why NCA is migrating
from Analogue to Digital Transmission.
(b) Wireless communication involves transfer of
information without any physical connection between
two or more points. Because of this absence of any
physical infrastructure, wireless communication has
certain advantages and disadvantages. Discuss the
most important ones with examples.
(c) In GSM systems the signal direction from the
mobile station to the network or the base station is
referred to as uplink. Why are lower frequencies given
to the uplink? A mobile network operator was
allocated uplink frequency (890-915MHz) and
downlink frequency (935-960MHz). Calculate the
number of available RF channels for this operator and
the duplex distance if the spectrum has a carrier
separation of 100kHz. Why are Telco’s more
interested in Radio channels?
In: Computer Science
Write a Python program containing a function named scrabble_sort that will sort a list of strings according to the length of the string, so that shortest strings appear at the front of the list. Words that have the same number of letters should be arranged in alphabetical order. Write your own logic for the sort function (you may want to start from some of the existing sorting code we studied). Do NOT use the built-in sort function provided by Python.
One optional way to test your function is to create a list of random words by using the RandomList function in PythonLabs and passing 'words' as an argument. For example:
>>> from PythonLabs.RecursionLab import *
>>> a = RandomList(20, 'words')
>>> scrabble_sort(a)
>>> print(a)
['mum', 'gawk', 'tree', 'forgo', 'caring', ... 'unquestioned']
Note: you do not need to include the above test case in your solution, but be sure to include at least 2 test cases to verify your scrabble_sort function works.
In PyCharm
In: Computer Science
For this problem you must write the functions in a recursive manner (i.e. the function must call itself) – it is not acceptable to submit an iterative solution to these problems.
A. Complete the recursive function gcd(m, n) that calculate the greatest common denominator of two numbers with the following rules:
# If m = n, it returns n
# If m < n, it returns gcd(m, n-m)
# If m > n, it returns gcd(m-n, n) #
def gcd(m,n): return None # Replace this with your implementation
B. Complete the following function that uses recursion to find and return the max (largest) value in the list u.
# find_max([1, 7, 4, 5] returns 7 # find_ max ([1, 7, 4, 5, 9, 2] returns 9 # def find_max(u):
return None # Replace this with your implementation
C. Complete the following recursive function that returns the zip of two lists u and v of the same length. Zipping the lists should place the first element from each into a new array, followed by the second elements, and so on (see example output).
# zip([1, 2, 3], [4, 5, 6]) returns [1, 4, 2, 5, 3, 6] # def zip(u, v):
return None # Replace this with your implementation
D. Complete the following recursive function that removes all occurrences of the number x from the list nums.
# remove_number(5, [1, 2, 3, 4, 5, 6, 5, 2, 1]) returns [1, 2, 3, 4, 6, 2, 1] # def remove_number(x, nums):
return None # Replace this with your implementation
E. Write a recursive function removeLetter(string, letter) that takes a string and a letter as input, and recursively removes all occurrences of that letter from the string. The function is case sensitive.
Some example test cases are below:
>>> removeLetter("test string", "t") es sring >>> removeLetter("mississipi", "i") mssssp
>>> removeLetter("To be or not to be is a question.", "t")
To be or no o be is a quesion.
In PyCharm
In: Computer Science
For the following, copy the questions into a text file and write your answers for each question.
I. Place the following algorithm time complexities in order from
fastest (least number of comparisons) to the slowest: nlogn, n, n2,
2n, logn, 2n
II. In your own words, explain the two characteristics that a
recursive solution must have.
III. Why are divide-and-conquer algorithms often very efficient in
terms of time complexity?
IV. Write in your own words 3 different examples of cases where
people around you are giving up their privacy to use some service
in exchange for a benefit. State for each example what data is
being collected and what benefits the user receives in
exchange.
In: Computer Science
C++ Program
Create Semester class (.h and .cpp file) with the
following three member variables:
▪ a semester name (Ex: Fall 2020)
▪ a Date instance for the start date of the semester
▪ a Date instance for the end date of the semester
The Semester class should have the following
member functions
1. Create a constructor that accepts three arguments: the semester
name, the start Date, and the end Date. Use default values for all
the parameters in the constructor
2. Overload the << operator for this
class
▪ Have it output the semester name and dates in a manner similar to
this:
Semester: Fall 2020 (08/31/2020 - 12/10/2020)
3. Overload the >> operator for this
class
▪ Have the >> operator accept input for the
Semester name, start date and end date.
4. Create the get and set functions for each variable - Do NOT
recreate the Date class - reuse code from Date Class.
Below is the Date .h and .cpp file
Date.h
========================================
#define DATE_H
#include <iostream>
using namespace std;
class Date
{
friend ostream& operator << (ostream&,
const Date&);
friend istream& operator >> (istream&,
Date&);
private:
int month;
int day;
int year;
void checkDate();
public:
Date(int = 1, int = 1, int = 1990);
~Date();
Date& setDate(int, int, int);
Date& setMonth(int);
Date& setDay(int);
Date& setYear(int);
int getMonth() const;
int getDay() const;
int getYear() const;
bool operator< (const Date&);
bool operator> (const Date&);
bool operator<= (const Date&);
bool operator>= (const Date&);
bool operator== (const Date&);
bool operator!= (const Date&);
};
Date.cpp
========================================
#include <iostream>
#include <iomanip>
#include "Date.h"
using namespace std;
Date::Date(int m, int d, int y)
{
setDate(m, d, y);
}
Date::~Date()
{
}
Date& Date::setDate(int m, int d, int y)
{
setMonth(m);
setDay(d);
setYear(y);
return *this;
}
void Date::checkDate()
{
static const int daysPerMonth[13] = { 0, 31, 28, 31,
30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (month <= 0 || month >= 12)
{
month = 1;
}
if (!(month == 2 && day == 29 &&
(year % 400 == 0 || (year % 4 == 0 && year % 100 !=
0)))
&& (day <= 0 || day >
daysPerMonth[month]))
{
day = 1;
}
if (year <= 1989)
{
year = 1990;
}
}
Date& Date::setMonth(int m)
{
month = m;
checkDate();
return *this;
}
Date& Date::setDay(int d)
{
day = d;
checkDate();
return *this;
}
Date& Date::setYear(int y)
{
year = y;
checkDate();
return *this;
}
int Date::getMonth() const
{
return month;
}
int Date::getDay() const
{
return day;
}
int Date::getYear() const
{
return year;
}
bool Date::operator<(const Date& right)
{
bool status;
if (year < right.year)
status = true;
else if ((year == right.year) && (month <
right.month))
status = true;
else if ((year == right.year) && (month <
right.month) && (day < right.day))
status = true;
else
status = false;
return status;
}
bool Date::operator>(const Date& right)
{
bool status;
if (year > right.year)
status = true;
else if ((year == right.year) && (month >
right.month))
status = true;
else if ((year == right.year) && (month >
right.month) && (day > right.day))
status = true;
else
status = false;
return status;
}
bool Date::operator<=(const Date& right)
{
bool status;
if (year <= right.year)
status = true;
else if ((year == right.year) && (month <=
right.month))
status = true;
else if ((year == right.year) && (month <=
right.month) && (day <= right.day))
status = true;
else
status = false;
return status;
}
bool Date::operator>=(const Date& right)
{
bool status;
if (year < right.year)
status = true;
else if ((year == right.year) && (month <
right.month))
status = true;
else if ((year == right.year) && (month <
right.month) && (day < right.day))
status = true;
else
status = false;
return status;
}
bool Date::operator==(const Date& right)
{
bool status;
if (year == right.year && month == right.month
&& day == right.day)
status = true;
else
status = false;
return status;
}
bool Date::operator!=(const Date& right)
{
bool status;
if (year != right.year && month != right.month
&& day != right.day)
status = true;
else
status = false;
return status;
}
ostream& operator<<(ostream& output, const
Date& obj)
{
output << setfill('0') << setw(2) <<
obj.month << '/' << setfill('0') << setw(2)
<< obj.day << '/' << obj.year;
return output;
}
istream& operator>>(istream& input, Date&
obj)
{
input >> obj.month;
input.ignore();
input >> obj.day;
input.ignore();
input >> obj.year;
obj.checkDate();
return input;
}
In: Computer Science
1. Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint.
public class Class1 {
public static String midString(String str) {
//Enter code here
}
}
-----------
2. Given an array of integers return the sum of the values stored in the first and last index of the array. The array will have at least 2 elements in it
public class Class1 {
public static int endSum(int[] values) {
//Enter code here
}
}
-----------
3. The method takes a string as a parameter. The method prints treat if the string is candy or chocolate (of any case, such as CaNdY) Otherwise print trick
import java.util.Scanner;
public class Class1 {
public static void trickOrTreat(String str) {
//Enter code here
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
trickOrTreat(s.nextLine());
}
}
In: Computer Science
(Area of a convex polygon)
A polygon is convex if it contains any line segment that connects
two points of the polygon. Write a program that prompts the user to
enter the number of points in a convex polygon, then enter the
points clockwise, and display the area of the polygon.
Sample Run
Enter the number of points: 7
Enter the coordinates of the points:
-12 0 -8.5 10 0 11.4 5.5 7.8 6 -5.5 0 -7 -3.5 -5.5
The total area is 244.575
In: Computer Science
CODE IN JAVA
Create a class Student includes name, age, mark and necessary methods. Using FileWriter, FileReader and BufferedReader to write a program that has functional menu:
Menu -------------------------------------------------
Your choice: _ |
+ Save to File: input information of several students and write that information into a text file, each student in a line (use tabs to separate the fields)
+ Read File: read and display information of students
In: Computer Science
JAVA code
Create a new class called BetterDiGraph that implements the EditableDiGraph interface See the interface below for details.
EditableDigraph below:
import java.util.NoSuchElementException;
/**
* Implements an editable graph with sparse vertex support.
*
*
*/
public interface EditableDiGraph {
/**
* Adds an edge between two vertices, v and w. If vertices do not
exist,
* adds them first.
*
* @param v source vertex
* @param w destination vertex
*/
void addEdge(int v, int w);
/**
* Adds a vertex to the graph. Does not allow duplicate
vertices.
*
* @param v vertex number
*/
void addVertex(int v);
/**
* Returns the direct successors of a vertex v.
*
* @param v vertex
* @return successors of v
*/
Iterable getAdj(int v);
/**
* Number of edges.
*
* @return edge count
*/
int getEdgeCount();
/**
* Returns the in-degree of a vertex.
* @param v vertex
* @return in-degree.
* @throws NoSuchElementException exception thrown if vertex does
not exist.
*/
int getIndegree(int v) throws NoSuchElementException;
/**
* Returns number of vertices.
* @return vertex count
*/
int getVertexCount();
/**
* Removes edge from graph. If vertices do not exist, does not
remove edge.
*
* @param v source vertex
* @param w destination vertex
*/
void removeEdge(int v, int w);
/**
* Removes vertex from graph. If vertex does not exist, does not try
to
* remove it.
*
* @param v vertex
*/
void removeVertex(int v);
/**
* Returns iterable object containing all vertices in graph.
*
* @return iterable object of vertices
*/
Iterable vertices();
/**
* Returns true if the graph contains at least one vertex.
*
* @return boolean
*/
boolean isEmpty();
/**
* Returns true if the graph contains a specific vertex.
*
* @param v vertex
* @return boolean
*/
boolean containsVertex(int v);
}
In: Computer Science
An ALP to print only lowercase alphabets[A-Z] using emu8086 and the code will be written like this form EX:
MOV AX, @DATA ; initialize
DS MOV DS, AX
and please write explanation when writing the code so we can understand it
In: Computer Science
****JAVA Program****
Make a LandTract class with the following fields:
• length - an int containing the tract's length
• width - an int containing the tract's width
The class should also have the following methods :
• area - returns an int representing the tract's area
• equals - takes another LandTract object as a parameter and
returns a boolean saying
whether or not the two tracts have the same dimensions (This
applies regardless of whether the dimensions match up. i.e., if the
length of the first is the same as the width of the other and vice
versa, that counts as having equal dimensions.)
• toString - returns a String with details about the LandTract
object in the format:
LandTract object with length 30 and width 40
(If, for example, the LandTract object had a length of 30 and a
width of 40.)
Write a separate program that asks the user to enter the dimensions
for the two tracts of
land (in the order length of the first, width of the first, length
of the second, width of the second). The program should print the
output of two tracts' toString methods followed by a sentence
stating whether or not the tracts have equal dimensions. (If the
tracts have the same dimensions, print, "The two tracts have the
same size." Otherwise, print, "The two tracts do not have the same
size.") Print all three statements on separate lines.
****Results have to look like this****
Enter·length·of·first·land·tract:10↵ Enter·width·of·first·land·tract:55↵ Enter·length·of·second·land·tract:36↵ Enter·width·of·second·land·tract:75↵ LandTract·with·length·10,·width·55,·and·area·550↵ LandTract·with·length·36,·width·75,·and·area·2700↵ The·two·tracts·do·not·have·the·same·size.↵
In: Computer Science