In: Computer Science
*******FOR A BIG THUMBS UP********
------INSTRUCTIONS---------
Coding standards note: The coding standards are in a document in a D2L module titled Coding Standards. See Grading Criteria for points lost if not followed.
Competencies being graded:
Problem Statement:
Create a program that reads in the file people.dat from Homework 2. (Yes, you can use the code from Homework 1). Please make sure to include Person.java in your submission.
Implement your own HashMap implementation. You may use the HashMap example provided in the notes, but you MUST modify it to handle Person objects only and bring it completely up to coding standards to receive all points. You MAY NOT use java.util.HashMap or java.util.TreeMap in this problem.
After reading in the Person objects, store the Personobjects into your HashMap implementation using the unique ID as the key to the map rather than the ArrayList used in Homework 2. Then print the Person objects from the HashMap in a user friendly fashion. You may use iterator or for-each loop-> DO NOT JUST System.out.println THE HASHMAP- ITERATE THROUGH IT. Hint: Modify your toString in Person to get a nice looking output.
------people.dat---------
¬í sr PersonM”fò(Ÿ# I idNumL cityt Ljava/lang/String;L
firstNameq ~ L lastNameq ~ xp t Bufordt Nanat
Agyemansq ~ t Dulutht Josepht Andersonsq ~ t Lawrencevillet Kylet
Brookssq ~ t Daculat Joshuat Broughtonsq ~ t Lilburnt
Demetrit Clarksq ~ t
Snellvillet Davidt Edwardssq ~ t Atlantat Jonit Elshanisq ~ t
Decaturt Jacobt Fagan
------peopleFile.txt-------
Nana
Agyeman
Buford
1
Joseph
Anderson
Duluth
2
Kyle
Brooks
Lawrenceville
3
Joshua
Broughton
Dacula
4
Demetri
Clark
Lilburn
5
David
Edwards
Snellville
6
Joni
Elshani
Atlanta
7
Jacob
Fagan
Decatur
8
--------Person.java-----------
import java.io.Serializable;
public class Person implements Serializable
{
public String firstName;
public String lastName;
public int idNum;
public String city;
/**
* Default constructor used to create empty
attributes
*/
public Person()
{
firstName = "";
lastName = "";
idNum = 0;
city = "";
}
/**
* @param firstName
* @param lastName
* @param idNum
* @param city
*/
public Person(String firstName, String lastName, int
idNum, String city)
{
this.firstName = firstName;
this.lastName = lastName;
this.idNum = idNum;
this.city = city;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return firstName + " " + lastName
;
}
/**
* @return the firstName
*/
public String getFirstName()
{
return firstName;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName()
{
return lastName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* @return the idNum
*/
public int getIdNum()
{
return idNum;
}
/**
* @param idNum the idNum to set
*/
public void setIdNum(int idNum)
{
this.idNum = idNum;
}
/**
* @return the city
*/
public String getCity()
{
return city;
}
/**
* @param city the city to set
*/
public void setCity(String city)
{
this.city = city;
}
}
----------GeneratePeopleFile.java-----------
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Scanner;
public class GeneratePeopleFile
{
public static void main(String[] args)
{
// Starting point of program
// open a file of Person class and
read them into an ArrayList of Persons
ArrayList<Person> people =
new ArrayList<Person>();
File peopleFile = new
File("peopleFile.txt");
// open a Scanner to read data from
File
Scanner peopleReader = null;
try
{
peopleReader =
new Scanner(peopleFile);
} catch (FileNotFoundException
e)
{
// TODO
Auto-generated catch block
System.out.println("File not found - terminating program");
System.exit(0);
e.printStackTrace();
}
// read one person at a
time
while
(peopleReader.hasNext())
{
// read first
name
String firstName
= peopleReader.next();
String lastName
= peopleReader.next();
String city =
peopleReader.next();
int id =
peopleReader.nextInt();
// create new
Person instance and add to ArrayList
Person temp =
new Person(firstName, lastName, id, city);
people.add(temp);
}
// print info to user
System.out.println("The people from
the file are:");
System.out.println(people);
// write people to another
file
File secondPeopleFile = new
File("people.dat");
ObjectOutputStream peopleWrite =
null;
try
{
peopleWrite =
new ObjectOutputStream(new FileOutputStream(secondPeopleFile));
for (Person
temp : people)
{
peopleWrite.writeObject(temp);
}
peopleWrite.close();
} catch (IOException e)
{
System.out.println("Problems writing to file");
// TODO
Auto-generated catch block
e.printStackTrace();
}
}
}
In: Computer Science
IN PSEUDOCODE and C++
Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame.
For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100). Write a program that asks the user for the starting X and Y position of the object as well as the starting X and Y velocity, then prints out its position each frame until the object moves off of the screen. Design (pseudocode) and implement (source code) for this program.
Sample run 1:
Enter the starting X position: 50
Enter the starting Y position: 50
Enter the starting X velocity: 4.7
Enter the starting Y velocity: 2
X:50 Y:50
X:54.7 Y:52
X:59.4 Y:54
X:64.1 Y:56
X:68.8 Y:58
X:73.5 Y:60
X:78.2 Y:62
X:82.9 Y:64
X:87.6 Y:66
X:92.3 Y:68
X:97 Y:70
X:101.7 Y:72
Sample run 2:
Enter the starting X position: 20
Enter the starting Y position: 45
Enter the starting X velocity: -3.7
Enter the starting Y velocity: 11.2
X:20 Y:45
X:16.3 Y:56.2
X:12.6 Y:67.4
X:8.9 Y:78.6
X:5.2 Y:89.8
X:1.5 Y:101
X:-2.2 Y:112.2
In: Computer Science
JAVA PROGRAMMING ASSIGNMENT - MUST USE ARRAYLIST TO SOLVE. OUTPUT MUST BE EXACT SAME FORMAT AS SAMPLE OUTPUT.
In this assignment, you will create a program implementing the functionalities of a standard queue in a class called Queue3503. You will test the functionalities of the Queue3503 class from the main() method of the Main class. In a queue, first inserted items are removed first and the last items are removed at the end (imagine a line to buy tickets at a ticket counter).
The Queue3503 class will contain:
a. An int[] data filed named elements to store the int values in the queue.
b. An int data field named size that stores the number of elements in the queue.
c. A no-arg constructor that creates a Queue object with default capacity 0.
d. A constructor that takes an int argument representing the capacity of the queue.
e. A method with signature enqueue(int v) that adds the int element v into the queue.
f. A method with signature dequeue() that removes and returns the first element of the queue.
g. A method with signature empty() that returns true if the queue is empty. h. A method with signature getSize() that returns the size of the queue (return type is hence int)).
The queue class you develop should be tested using the following steps: (In other words, your program named Main will consist of the following)
a. Start your queue with an initial capacity of 8.
b. When the dequeue() method is called, an element from the queue at the beginning of the queue must be removed.
c. The main() method in your Main class should consist of statements to:
i. Create a queue object;
ii. Call enqueue() to insert twenty integers (taken from the user) into the queue.
iii. After the above task is completed, include a for-loop that will print out the contents of the queue.
d. After printing the queue filled with twenty integers, call dequeue() repeatedly to remove the beginning element of the queue.
e. Print the contents of the queue after removing every fifth number.
f. For your reference, the execution of the Main program is shown below. User inputs for populating the Queue is shown in the first line. Next, your program outputs are shown.
Sample Run
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Initial content: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
After removing 5 elements: 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
After removing 5 elements: 11 12 13 14 15 16 17 18 19 20
After removing 5 elements: 16 17 18 19
In: Computer Science
In: Computer Science
(write a program that get the numbers from user and search the file numbers.text for that value. in C++) numbers.txt: 10 23 43 5 12 23 9 8 10 1 16 9
you must to have the exact output:
Enter a number: 10
10 last appears in the file at position 9
Enter a number: 29
29 does not appear in the file
Enter a number: 9
9 last appears in the file at position 12
Enter a number:
In: Computer Science
Please, write code in c++. Using iostream library
Most modern text editors are able to give some statistics about
the text they are editing. One nice statistic is the average word
length in the text. A word is a maximal continuous sequence of
letters ('a'-'z', 'A'-'Z'). Words can be separated by spaces,
digits, and punctuation marks. The average word length is the sum
of all the words' lengths divided by the total number of
words.
For example, in the text "This is div2 easy problem". There are 5 words: "This"is"div"easy" and "problem". The sum of the word lengths is 4+2+3+4+7 = 20, so the average word length is 20/5 = 4.
Given a text, return the average word length in it. If there are no words in the text, return 0.0.
Input
The first line will contain the text of length between 0 and 50
characters inclusive. Text will contain only letters ('a'-'z',
'A'-'Z'), digits ('0'-'9'), spaces, and the following punctuation
marks: ',', '.', '?', '!', '-'. The end of text will be marked with
symbol '#' (see examples for clarification).
Output
Output should contain one number - the average length. The returned
value must be accurate to within a relative or absolute value of
10-9.
Samples:
| № | Input | Output |
|---|---|---|
| 1 | This is div2 easy problem.# | 4.0 |
| 2 | a bc# | 1.5 |
| 3 | w84lFC1hD2ot2?43 Jnw67Kmt8KhOQn# | 2.714285714 |
In: Computer Science
Compare Google and Yahoo in the impact of data sharing and data privacy on on-line consumers in the U.S.
(100 words min )
In: Computer Science
Write a Scheme function that takes two integers and returns the list of all integer numbers between these two integers (inclusively) in increasing order. (numbers 10 20) (10 11 12 13 14 15 16 17 18 19 20)
Please explain every step.
In: Computer Science
C++, Need to create a code that will calculated the statistics for character input?
This is the prompt for the code. I truly understand nothing of what it's asking.
Ask the user for one character (terminated by a carriage return).Using flow control, classify the character into one of these categories:
1) vowel
2) consonant
3) digit (0-9)
4) other
Output the character input, its numeric decimal value, and the classification. Total up the number of each type of character entered. After the character is entered, ask the user if they want to continue (Y/N). When they enter N, you can stop prompting for more characters. Make sure to validate for Y or N data entry. Then display the total number of each type of characters entered.
In: Computer Science
For the following Paging configuration discuss what must be done
to ensure a processes address space is not violated.
Process with five pages of 2048 words.
In: Computer Science
Find the bit length of a LAN if the data rate is 1 Gbps and the medium length in meters for a communication between two stations is 200 m. Assume the propagation speed in the medium is 2 *10^8 m/s.
In: Computer Science
Objectives
Problem Specification
Skip by 7’s and 9’s
1. Generate n numbers between -100 and 100.
2. If the value is multiple of 7 or 9, replaced by *
3. Then change to new line after the multiple of 7 or 9 is appeared
Design Specification
Example:
In: Computer Science
Java Program. Please read carefully. i need the exact same output as below. if you unable to write the code according to the question, please dont do it. thanks
To the HighArray class in the highArray.java program (Listing 2.3), add the following methods:
1. getMax() that returns the value of the highest key (value) in the array without removing it from the array, or –1 if the array is empty.
2. removeMax() that removes the item with the highest key from the array.
3. reverse() method for the HighArray class to reverse the order of elements of the array.
Sample output of HighArray class once you do the above methods:
current array items: 77 99 44 55 22 88 11 0 66 33
Can't find 35
array items after delete some values: 77 44 22 88 11 66 33
the Max is 88
the array after calling max method: 77 44 22 88 11 66 33
the array after calling remove max method: 77 44 22 11 66 33
the new max is 77
the array after calling reverse method 33 66 11 22 44 77
In: Computer Science
Given an IP address and mask of 192.168.0.0 /24 (address / mask), design an IP addressing scheme that satisfies the following requirements. Network address/mask and the number of hosts for Subnets A and B will be provided by your instructor.
|
Subnet |
Number of Hosts |
|
Subnet A |
55 |
|
Subnet B |
25 |
The 0th subnet is used. No subnet calculators may be used. All work must be shown on the other side of this page.
|
Subnet A |
|||
|
Specification |
Student Input |
Points |
|
|
Number of bits in the subnet |
(5 points) |
||
|
IP mask (binary) |
|||
|
New IP mask (decimal) |
|||
|
Maximum number of usable subnets (including the 0th subnet) |
|||
|
Number of usable hosts per subnet |
|||
|
IP Subnet |
|||
|
First IP Host address |
|||
|
Last IP Host address |
|||
|
Subnet B |
|||
|
Specification |
Student Input |
Points |
|
|
Number of bits in the subnet |
(5 points) |
||
|
IP mask (binary) |
|||
|
New IP mask (decimal) |
|||
|
Maximum number of usable subnets (including the 0th subnet) |
|||
|
Number of usable hosts per subnet |
|||
|
IP Subnet |
|||
|
First IP Host address |
|||
|
Last IP Host address |
|||
Host computers will use the first IP address in the subnet. The network router will use the LAST network host address. The switch will use the second to the last network host address.
Write down the IP address information for each device:
|
Device |
IP address |
Subnet Mask |
Gateway |
Points |
|
PC-A |
(5 points) |
|||
|
R1-G0/0 |
N/A |
|||
|
R1-G0/1 |
N/A |
|||
|
S1 |
N/A |
|||
|
PC-B |
In: Computer Science