In: Computer Science
import javax.swing.*;
public class MenuFrame extends JFrame {
public MenuFrame() {
setTitle("Menu Frame");
setSize(500, 500);
MenuListenerExample myMenu = new
MenuListenerExample();
setJMenuBar(myMenu);
setLayout(null);
add(myMenu.textArea);
}
public static void main(String[] args) {
MenuFrame frame = new MenuFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.event.*;
public class MenuListenerExample extends JMenuBar
{
JMenu fileMenu, editMenu, helpMenu;
JMenuItem cut, copy, paste, selectAll;
JTextArea textArea;
public MenuListenerExample() {
cut = new JMenuItem("cut");
copy = new JMenuItem("copy");
paste = new JMenuItem("paste");
selectAll = new JMenuItem("selectAll");
textArea = new JTextArea();
cut.addActionListener(new MenuAction());
copy.addActionListener(new MenuAction());
paste.addActionListener(new MenuAction());
selectAll.addActionListener(new
MenuAction());
fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
helpMenu = new JMenu("Help");
editMenu.add(cut);
editMenu.add(copy);
editMenu.add(paste);
editMenu.add(selectAll);
add(fileMenu);
add(editMenu);
add(helpMenu);
textArea.setBounds(30, 30, 430, 400);
}
private class MenuAction implements ActionListener
{
public void actionPerformed(ActionEvent e) {
if (e.getSource() == cut) {
textArea.cut();
}
if (e.getSource() == paste) {
textArea.paste();
}
if (e.getSource() == copy) {
textArea.copy();
}
if (e.getSource() == selectAll) {
textArea.selectAll();
}
}
}
}
modify the above Java program to include the following: - When the
user clicks on the help menu, a drop-down list will appear with an
item called About, then when the user clicks on it, the window will
show some instructions about the functionality of the menu, e.g,
what the edit menu does, etc. - When the user clicks on the File
menu, a drop-down list will appear with one item called Show
Picture, and when the user clicks on it, a picture of your choice
will appear.
In: Computer Science
Question 4
A. Suppose the following letter grade class has been defined globally in a program.
#include <iostream>
using namespace std;
class Grade {
private:
char grade;
public:
Grade(char in_grade);
void print( );
};
Grade::Grade ( char in_grade) {
grade = in_grade;
}
void Grade::print ( ) {
cout << grade;
}
Write a main function that reads one character from the keyboard, create a Grade object containing that character, and then have the object print itself.
Furthermore, create an output file (named “output.txt”), and save the character to this output file. Last, close this output file.
int main ( )
{
int a = 3, b= 2, c= 1, d, e, f, g;
d = a&b; e = a | c; f = a >> 1, g = a << 1;
cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl;
}
In: Computer Science
Consider the following variation of merge sort: split the list into thirds, sort each third, and then merge all three sorted lists.
(a) Write pseudo-code for this sorting algorithm in python.
(b) Write a recurrence relation for the run-time of this algorithm, and use the master theorem to find the “big O” run time of the algorithm.
(c) How does the run time compare to the usual merge sort? Is this an improvement?
In: Computer Science
What is the Big-Oh notation of the following code snippet:
BinarySearch(numbers, N, key) {
mid = 0;
low = 0;
high = 0;
high = N - 1;
while (high >= low) {
mid = (high + low) / 2
if (numbers[mid] < key) {
low = mid + 1
}
else if (numbers[mid] > key) {
high = mid - 1
}
else {
return mid
}
}
return -1 // not found }
In: Computer Science
1. what is accessibility and assistive technology in web design? give one example for how assistive technology might support accessibility.
2. file formats like JPEG, GIF and PNG are supported by web browsers. which file format would you suggest be used to store the below given images? Expalain your reason for suggestion that particular file format
i) A picture of brightly coloured pigeon
ii) A railway network map showing routes between two towns
In: Computer Science
I need this in JAVA
Lab9B In each method returned an integer. In this part of the lab, all methods will have a void return type and take in an array of integers as a parameter. You’re going to write a program that creates a mini database of numbers that allows the user to reset the database, print the database, add a number to the database, find the sum of the elements in the database, or quit.
In main, you will declare an array of 10 integers (this is a requirement). Then you will define the following methods:
• printArray (int[ ] arr) – this takes in an array and prints it
• initArray (int[ ] arr) – this initializes the array so that each cell is 0
• printSum (int[ ] arr) – this calculates the sum of the elements in the array and prints it
• enterNum(int[ ] arr) – this asks the user for a slot number and value – putting the value into the array in the correct slot
• printMenu (int[ ] arr) – prints the menu in the sample output (that’s it, nothing more)
In main, create an array of 10 integers and immediately call initArray( ). Then, continuously looping, print the menu and ask the user what they want to do – calling the appropriate methods based on the user’s choice. Note that every time you call a method, you must pass the array that was created in main. If it makes it easier, we used a do-while loop and a switch statement in main. In our implementation, main was only 15 lines of code.
Sample output #1 Would you like to:
1) Enter a number
2) Print the array
3) Find the sum of the array
4) Reset the array
5) Quit
1
Enter the slot: 5
Enter the new value: 76
Would you like to: 1)
Enter a number 2)
Print the array 3)
Find the sum of the array 4)
Reset the array 5)
Quit
In: Computer Science
Suppose the following letter grade class has been defined globally in a program.
#include <iostream> using namespace std;
class Grade { private:
char grade; public:
Grade(char in_grade); }; void print( );
Grade::Grade ( char in_grade) { } grade = in_grade;
void Grade::print ( ) {
cout << grade; }
1.Write a main function that reads one character from the keyboard, create a Grade object containing that character, and then have the object print itself.
2. Furthermore, create an output file (named “output.txt”), and save the character to this output file. Last, close this output file. (Answer this question).
In: Computer Science
Explain the java class below, how it make:
import java.util.*;
import java.util.concurrent.TimeUnit;
public class RacingGame {
ArrayList<Driver> player = new
ArrayList<Driver>();
CarType car = new
CarType("Ferrari","2018",280,90,15);
Formula formula = new Formula(5);// number of
laps
long startTime = System.currentTimeMillis();
long currentTime = System.currentTimeMillis();
int totalDis = 0;
public static void main(String[] args)
{
RacingGame formulaRace = new
RacingGame();
formulaRace.player.add(new
Driver("Saleh",10,3));
formulaRace.formula.setDistance(20);//lap distance
formulaRace.totalDis =
formulaRace.formula.getTotalDistance();
formulaRace.formula.setDistance(formulaRace.totalDis);
formulaRace.raceStatus();
}
public void raceStatus()
{
int newSpeed = 0;
long diff = 0;
long sec = 0;
while (formula.distance >
0)
{
currentTime =
System.currentTimeMillis();
diff =
currentTime - startTime;
sec =
diff/1000;
newSpeed = (int)
sec * car.getAcceleration();
car.setSpeed((int)(newSpeed + (newSpeed*
((double)player.get(0).getExperince()/10) *
((double)player.get(0).getLevel()/100))));
int newDistance
= (int) (formula.distance - ((car.getSpeed()*sec))/3600);
formula.setDistance(newDistance);
int
traveledDistance = totalDis - newDistance;
System.out.println("Driver name: " + player.get(0).getPlayerName()
+ ", current Speed: " + car.getSpeed() + " km/h, Traveled distance:
" + traveledDistance + " km");
try {
TimeUnit.SECONDS.sleep(1);
} catch
(InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("Driver name: "
+ player.get(0).getPlayerName() + " finished the race in " + sec +
" seconds");
}
}
//Driver(String playerName, int year, int level, String
experienceType)
//CarType(String model, String year, int maxSpeed, int balance,
double acceleration)
In: Computer Science
This question is to let you understand the impact of radio channel condition on wireless transmission and to learn how performance may be improved by re-transmitting small ACK packets.
A satellite is orbiting the earth at the geostationary orbit. It relays packets between two ground stations on the surface of the earth. The distance between the satellite and the ground stations is 72000 km. Ground station A sends a 1500 bytes packet to the satellite and the satellite forwards it (after it has been completely and successfully received by the satellite) to the ground station B. Ground station B replies with a 30 bytes ACK which is subsequently received by the satellite and forwarded to ground station A (again, it is forwarded, after the satellite has completely and successfully received the ACK packet.) Assume that the bit error rate of the channel from ground station to satellite (and vice versa) is 10^(-5). Assume that the ground station A knows exactly the time at which the ACK would have to be received for its transmitted packet. If an error-free ACK has not been received by that time, the ground station A re-sends the data packet. Let the propagation delay be at the speed of light. Also assume that the data transmission speed on all stations and the satellite to be 1Mb/sec.
What is the average time it takes until the packet is confirmed as delivered (time between start of first transmission from ground station A until an error-free ACK has been completely received by the ground station A)? What is the average time it takes if the bit error rate is degraded to 10^(-3)?
In: Computer Science
javascript
9. “User Info”, submenu of “Setting”.
9.1 _____ (10 pts) A submenu is under “setting”. When the user
clicks on “User Info”, a pop up window
should display the user information (name, gender).
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="navbar">
<div class="subnav">
<button class="subnavbtn">File <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
<input id="csvfile" type="file" style="display:none" />
<a href="#" id="loadCSV">Load CSV file</a>
<a href="#" id='navLoginDB' onclick="return loginDB('show');">Login to DB</a>
<a href="#" id='navLogoutDB' onclick="return logoutDB();">Logout DB</a>
<a href="#">Exit</a>
</div>
</div>
<div class="subnav">
<button class="subnavbtn">View <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
<a href="#">Line</a>
<a href="#">Pie</a>
<a href="#">Bar</a>
<a href="#">Map</a>
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Setting <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
<a href="#link1">User Info</a>
</div>
</div>
<div class="subnav">
<button class="subnavbtn">Help <i class="fa fa-caret-down"></i></button>
<div class="subnav-content">
<a href="#">Info</a>
<a href="#">Client</a>
</div>
</div>
</div>
<div id="dvCSV">
</div>
<script>
$(document).ready(function () {
var browserSupportFileUpload = function () {
var isCompatible = false;
if (window.File && window.FileReader && window.FileList && window.Blob) {
isCompatible = true;
}
return isCompatible;
};
if (browserSupportFileUpload()) {
document.getElementById('csvfile').addEventListener('change', uploadFile, false);
} else {
$("#message").html('The File APIs is not fully supported in thie browser. please use another browser.');
}
$(function () {
$("#loadCSV").click(function(e){
//$("#loadCSV").on('click', function (e) {
e.preventDefault();
$("#csvfile:hidden").trigger('click');
});
});
var uploadFile = function (event) {
var file = event.target.files[0];
var fileformat;
if (file.name.indexOf("csv") != -1) {
fileformat = true;
}
else {
fileformat = false;
}
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function (event) {
if ((file.size / Math.pow(1024, 3)) > navigator.deviceMemory) {
document.getElementById("message").innerHTML = "The data requires more memory than the client can offer";
}
else if (!fileformat) {
document.getElementById("message").innerHTML = "The data is in wrong format. Only CSV file can be loaded!";
}
else {
createArray($.csv.toArrays(event.target.result));
}
};
};
function createArray(data) {
if (data !== null && data !== "" && data.length > 1) {
this.CSVdata = data;
document.getElementById("message").innerHTML = " File upload successful with" + ((CSVdata.length) - 1) + " records! lower threshold is:" + highlight('OutlierL') + " upper threshold is: " + highlight('OutlierU');
var wage = findAvg('Avg');
var pop = findAvg('Pop');
if (getCookie("p1UserName") != "") {
var uname = getCookie("p1UserName");
$.ajax({
url: "",
type: 'POST',
async: false,
data: {
uname: uname
},
success: function (response) {
var dd = JSON.parse(response);
console.log(dd);
wage = parseFloat(dd[0][0]);
pop = parseFloat(dd[0][1]);
}
});
}
}
}
}
);
</script>
</body>
</html>
style.css
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
}
.navbar {
overflow: hidden;
background-color: #333;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.subnav {
float: left;
overflow: hidden;
}
.subnav .subnavbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .subnav:hover .subnavbtn {
background-color: red;
}
.subnav-content {
display: none;
position: absolute;
left: 0;
background-color: red;
width: 100%;
z-index: 1;
}
.subnav-content a {
float: left;
color: white;
text-decoration: none;
}
.subnav-content a:hover {
background-color: #eee;
color: black;
}
.subnav:hover .subnav-content {
display: block;
}
#upload {
display: block;
visibility: hidden;
width: 0;
height: 0;
}
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
In: Computer Science
The speed at which a processor can process instructions can be increased by making its clock speed higher, or by increasing the amount of L1 cache memory on the processor chip.
Explain the terms clock speed and L1 cache and briefly discuss how increasing each of them increases the speed at which instructions can be processed.
The maximum word limit for Question 3(a) is 150 words.
b.You have the choice of buying two processors:
In order to decide which to buy, you decide to estimate the time each processor will take to process a program with 10,000 RISC instructions. Each RISC instruction takes one clock pulse to execute once it is in the registers, and has a size of 4 bytes.
How much time is needed to load all 10,000 instructions into the registers for each processor. Write your answers in seconds, using scientific notation.
You may assume that no data is needed for this test program. in each case you will only need to calculate the time to move 10,000 instructions into the registers and the time to execute the 10,000 instructions. You will then find the total time for each processor by adding these two values.
Write your answers in seconds, using scientific notation.
In: Computer Science
NOTE THAT
((This should be done by R studio !))
Q: Upload your data as a CSV in R studio, then do
any
cleaning or convert needed for example convert the date in your
table
from character to date and NA identifiers . After
do all these, run a summary statistics
|
Year |
REX |
OilP |
Food exports (% of merchandise exports) |
Ores and metals exports (% of merchandise exports) |
|
1980 |
239.5433424 |
35.52 |
0.09638294 |
0.060083757 |
|
1981 |
240.3102173 |
34 |
0.094079554 |
0.024360528 |
|
1982 |
245.3895131 |
32.38 |
0.128489839 |
0.025668368 |
|
1983 |
242.8677506 |
29.04 |
.. |
.. |
|
1984 |
238.0284197 |
28.2 |
.. |
.. |
|
1985 |
221.878717 |
27.01 |
0.259787311 |
0.116943755 |
|
1986 |
169.6457184 |
13.53 |
.. |
.. |
|
1987 |
144.1934823 |
17.73 |
.. |
.. |
|
1988 |
134.5212315 |
14.24 |
1.371078529 |
0.732151804 |
|
1989 |
136.0536024 |
17.31 |
1.374888969 |
0.834330299 |
|
1990 |
125.5311345 |
22.26 |
0.713126234 |
0.491007478 |
|
1991 |
125.8812467 |
18.62 |
0.526384845 |
0.242750346 |
|
1992 |
118.7733668 |
18.44 |
1.074388363 |
0.548851562 |
|
1993 |
122.2521688 |
16.33 |
0.982275388 |
0.429968062 |
|
1994 |
117.8952881 |
15.53 |
0.673955645 |
0.346686956 |
|
1995 |
114.1213899 |
16.86 |
0.810242733 |
0.567217625 |
|
1996 |
116.3114665 |
20.29 |
0.632336949 |
0.304958406 |
|
1997 |
121.4661302 |
18.86 |
.. |
.. |
|
1998 |
127.1948915 |
12.28 |
1.114818605 |
0.507089276 |
|
1999 |
121.9490893 |
17.44 |
0.930990348 |
0.262574488 |
|
2000 |
123.200674 |
27.6 |
0.538501429 |
0.147164016 |
|
2001 |
125.2424379 |
23.12 |
0.558465111 |
0.201693533 |
|
2002 |
121.5455166 |
24.36 |
0.628539417 |
0.223275991 |
|
2003 |
111.1523893 |
28.1 |
0.835851768 |
0.182707717 |
|
2004 |
103.4682918 |
36.05 |
0.7405123 |
0.172800798 |
|
2005 |
100.5070052 |
50.59 |
0.620831971 |
0.137293785 |
|
2006 |
98.93290899 |
61 |
0.64203501 |
0.219532433 |
|
2007 |
95.96813741 |
69.04 |
0.838923226 |
0.283587719 |
|
2008 |
93.62494305 |
94.1 |
0.744029125 |
0.221986187 |
|
2009 |
100.1652448 |
60.86 |
1.407633083 |
0.232499732 |
|
2010 |
100 |
77.38 |
1.155876888 |
0.154654215 |
|
2011 |
96.57013945 |
107.46 |
0.898301922 |
0.122271232 |
|
2012 |
99.61967144 |
109.45 |
0.860627792 |
0.138455596 |
|
2013 |
102.3680362 |
105.87 |
0.878931429 |
0.403127249 |
|
2014 |
105.3894897 |
96.29 |
1.006265279 |
0.769034983 |
|
2015 |
118.5851177 |
49.49 |
1.798068624 |
1.307540253 |
R ONLY !!
In: Computer Science
System Analysis and Design
On the Spot Courier Services
As On the Spot Courier Services continues to grow, Bill discovers that he can provide much better services to his customers if he utilizes some of the technology that is currently available. For example, it will allow him to maintain frequent communication with his delivery trucks, which could save transportation and labor costs by making the pickup and delivery operations more efficient. This would allow him to serve his customers better. Of course, a more sophisticated system will be needed, but Bill's development consultant has assured him that a straightforward and not-too complex solution can be developed.
Here is how Bill wants his business to operate. Each truck will have a morning and afternoon delivery and pickup run. Each driver will have a portable digital device with a touch screen. The driver will be able to view his or her scheduled pickups and deliveries for that run. (Note: This process will require a new use case something the Agile development methodology predicted would happen.) However, because the trucks will maintain frequent contact with the home office via telephony Internet access, the pickup/delivery schedule can be updated in real time even during a run. Rather than maintain constant contact, Bill decides that it will be sufficient if the digital device synchronizes with the home office whenever a pickup or delivery is made. At those points in time, the route schedule can be updated with appropriate information.
Previously, customers were able to either call On the Spot and request a package pickup or visit the company's Web site to schedule a pickup. Once customers lugged in, they could go to a Web page that allowed them to enter information about each package, including "deliver to" addresses, size and weight category information, and type of service requested. On the Spot provided "three hour," "same day," and "overnight- services. To facilitate customer self-service, On the Spot didn't require exact weights and sizes, but there were predefined size and weight categories from which the customer could choose.
Once the customer entered the information for all the packages, the system would calculate the cost and then print mailing labels and receipts. Depending on the type of service requested and the proximity of a delivery truck, the system would schedule an immediate pickup or one for later that day. It would display this information so the customer would immediately know when to expect the pickup.
Picking up packages was a fairly straight forward process. But there was some variation in what would happen depending on what information was in the system and whether the packages were already labeled. Upon arriving at the scheduled pickup location, the driver would have the system display any package information available for this customer. If the system already had information on the packages, the driver would simply verify that the correct information was already in the system for the packages. The driver could also make such changes as correcting the address, deleting packages, or adding new packages. If this were a cash customer, the driver would collect any money and enter that into the system. Using a portable printer from the van, the driver could print a receipt for the customer as necessary. If there were new packages that weren't in the system, the driver would enter the required information and also print mailing labels with his portable printer.
One other service that customers required was to be able to track the delivery status of their packages. The system needed to track the status of a package from the first time it "knew" about the package until it was delivered. Such statuses as "ready for pickup," "picked up," "arrived at warehouse," "out for delivery," and "delivered" were important. Usually, a package would follow through all the statuses, but due to the sophistication of the scheduling and delivery algorithm, a package would sometimes be picked up and delivered on the same delivery run. Bill also decided to add a status of "canceled" for those packages that were scheduled to be picked up but ended up not being sent.
a. Draw a Domain Class Diagram of your entire system.
b. For the Use Case Request a Package Pickup:
i.Write a Fully Developed Use Case description.
ii. Draw an Activity Diagram.
iii. Draw an SSD.
In: Computer Science
For this week let’s discuss the concepts of primary keys and table indexes.
Give some examples of data types and fields that you might use for certain scenarios and also what types are not good to use.
In: Computer Science