This programming assignment involves learning about some common exceptions which occur in Java programs. Consider the following exception types:
NullPointerException
ArrayIndexOutOfBounds
Exception ClassCastException
IllegalArgumentException
Research what each exception type means and the conditions under which each occurs (thrown). Then write the following programs, one for each of the above-listed exception types:
A program which throws the exception (with a throw statement) and catches it displaying unique information about the exception. Name your programs <exception>Thrown.java
<exception> is the name of the exception involved for example NullPointerExceptionThrown.java.
A program which causes the exception to be thrown (not with a throw statement) and catches it displaying unique information about the exception (ex. Name of class and method causing the exception). For example, for the NullPointerException, have your program create a situation which would cause this exception to be thrown. Name your programs <exception>Catch.java <exception> is the name of the exception involved for example NullPointerExceptionCatch.java.
At the end you should have eight programs, four <exception>Thrown.java and four <exception>Catch.java. All files should be in the same directory.
In: Computer Science
Complete the following assignment in C programming language.
In: Computer Science
topic : Introduction to TCP/IP
1) The explanation of how data flows through the network?
2) Understanding of TCP/IP architecture and layers and comparison
with the OSI layers?
3) Understanding of the role of protocol analysis in network
management?
topic : Name Resolution on IP
Network
4) Fundamentals of name resolution protocols ?
5) How name resolution works in IPv4 networks, including the DNS
database structure, the DNS namespace, DNS database records, the
delegation of DNS authority, and the different types of DNS
servers, and explain how name servers work?
6) How name resolution works on IPv6 networks, including the use of
AAAA records,the use of source &destination address selection,
how rules are organized by the source and destination address
algorithms, & end-to-end address selection process?
topic : Transport Layer Protocols
7) Understanding of the differences between connectionless and
connection-oriented transport mechanisms?
8) Explain understanding of key features and functions of the User
Datagram Protocol (UDP) and the Transmission Control Protocol (TCP)
?
In: Computer Science
(To be written in Java code)
A personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list.
Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries.
Use the following names and phone numbers:
| Name | Phone # |
|---|---|
| Gina | (847) 341-0912 |
| Marcia | (847) 341-2392 |
| Rita | (847) 354-0654 |
| Jennifer | (414) 234-0912 |
| Fred | (414) 435-6567 |
| Neil | (608) 123-0904 |
| Judy | (608) 435-0434 |
| Arlene | (608) 123-0312 |
| LaWanda | (920) 787-9813 |
| Deepak | (930) 412-0991 |
This code was provided to start with:
import java.util.*;
class PhoneNumbers
{
public static void main (String[] args)
{
// write code here
}
}
In: Computer Science
Use JAVA to Design a simple registration system that allows Student to register in a course.
Requirements
In: Computer Science
My question is on this program I have difficulty i marked by ???
public class SortedSet { private Player[] players; private int count;
public SortedSet() { this.players = new Player[10]; }
/** * Adds the given player to the set in sorted order. Does not add
* the player if the case-insensitive name already exists in the set.
* Calls growArray() if the addition of the player will exceed the size
* of the current array. Uses an insertion sort algorithm to place the
* new player in the correct position in the set, taking advantage of
* the private swapPlayers method in this class.
* * @param player the player to add
* @return the index where the player was added, or -1 if not added
*/
public int add(Player player) {
My question is how to add sorted order with the player in the case-insensitive
????????????????????????????????????????????????????? and
return -1;
}
/**
* @param name the name of the player to remove
* @return true if removed, false if not found
*/
public boolean remove(String name) {
??????????????????????????????????????????????????????????????????????
How to removes the player with the given case-insensitive name from the set. return true;
}
/**
* @param name the player's name
* @return the index where the player is stored, or -1 if not found
*/
public int find(String name) {
?????????????????????????????????????????????????????????
How to Locates the player with the given case-insensitive name in the set. return 0;
}
/**
* @param index the index from which to retrieve the player
* @return the player object, or null if index is out of bounds.
*/
public Player get(int index) {
?????????????????????????????????????????????????????????
How to returns the player object stored at the given index. return null;
}
/**
* Provides access to the number of players currently in the set.
* @return the number of players */ public int size() { return count;
}
/**
* Provides access to the current capacity of the underlying array.
* @return the capacity of the array
*/
public int capacity() { return players.length;
}
/** Provides a default string representation of th sorted set. Takes
* advantage of Player's toString method to provide a single line String.
* Example: [ (Player: joe, Score: 100) (Player: fred, Score: 98) ]
* @return the string representing the entire set
*/ @Override
public String toString() {
??????????????????????????????????????
How to provides a default string ?????????
return null;
}
/**
* @param i the first index
* @param j the second index
*/
private void swapPlayers(int i, int j) {
??????????????????????????????????????????????????????
How to private method used during sorting to swap players in the underlying array.
}
private void growArray() {
???????????????????????????????????????????????????????????
How to private method used to double the array if adding a new player will exceed the size of the current array.
}
}
//----------------------------------------------------------------------------------------------------------------------------// //
players Classes public class Player implements Comparable {
//
fields private String name; private int score;
/**
* Full constructor.
* @param name the player's name
* @param score the player's highest score
*/
public Player(String name, int score) {
this.name = name; this.score = score;
}
/**
* Provides access to the player's name.
* @return the player's name
*/
public String getName() {
return name;
}
/**
* Allows the player's name to be set.
* @param name the player's name
*/
public void setName(String name) {
this.name = name;
}
/**
* Provides access to the player's highest score.
* @return the player's highest score
*/
public int getScore() {
return score;
}
/**
* Allows the player's highest score to be set.
* @param score the player's highest score
*/
public void setScore(int score) {
this.score = score;
}
/**
* Provides a default string representation of an object of this class.
* @return */ @Override public String toString() {
return "Player: " + name + ", Score: " + score;
}
/** * Provides a unique hash code for this object,
* based on the case-insensitive player name.
* @return the hash code
*/
@Override public int hashCode() {
int hash = 3;
hash = 83 * hash + Objects.hashCode(this.name.toLowerCase());
return hash;
}
/** * Reports if the given object is equal to this object,
* based on the case-insensitive player name.
* * @param obj the object to compare to this one
* @return true if the names are the same, false if not.
*/ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Player other = (Player) obj;
return this.name.equalsIgnoreCase(other.name);
}
/** * Compares the given object with this one to determine sort order.
* * @param other the other object to compare to this one
* @return a negative value if this object should come before the other one,
* a positive value if it should come after, or zero if they are the same
*/ @Override public int compareTo(Player other) { return other.score - this.score; } }
//----------------------------------------------------------------------------------------------------------------------------//
// Main class
public class Lab1 {
/** * All tests performed here in main method.
* * @param args the command line arguments
*/
public static void main(String[] args) {
SortedSet set = new SortedSet();
//test insertion for (int i = 0; i < 10; i++) {
if (set.add(new Player(String.valueOf((char) (i + 97)), i + 10)) != 0) {
System.out.println("INSERTION FAIL"); return; }
}
System.out.println("INSERTION PASS");
//test growing array
if (set.add(new Player("k", 9)) != 10) {
System.out.println("GROW FAIL"); return;
}
System.out.println("GROW PASS");
//test duplicate
if (set.add(new Player("D", 5)) != -1) {
System.out.println("DUPLICATE FAIL");
return;
}
System.out.println("DUPLICATE PASS");
//test valid remove
if (!set.remove("c")) {
System.out.println("VALID REMOVE FAIL");
return;
}
System.out.println("VALID REMOVE PASS");
//test invalid remove if (set.remove("z")) {
System.out.println("INVALID REMOVE FAIL");
return;
}
System.out.println("INVALID REMOVE PASS");
//test valid find
if (set.find("g") != 3) {
System.out.println("VALID FIND FAIL");
return;
}
System.out.println("VALID FIND PASS");
//test invalid find
if (set.find("z") != -1) {
System.out.println("INVALID FIND FAIL");
return;
}
System.out.println("INVALID FIND PASS");
//test valid get
if (set.get(0).getScore() != 19) {
System.out.println("VALID GET FAIL");
return;
}
System.out.println("VALID GET PASS");
//test invalid
get if (set.get(100) != null) {
System.out.println("INVALID GET FAIL");
return;
}
System.out.println("INVALID GET PASS");
//test toString method try { String str = set.toString();
if (str.equals("[ (Player: j, Score: 19) (Player: i, Score: 18) " + "(Player: h, Score: 17) (Player: g, Score: 16) " + "(Player: f, Score: 15) (Player: e, Score: 14) " + "(Player: d, Score: 13) (Player: b, Score: 11) " + "(Player: a, Score: 10) (Player: k, Score: 9) ]")) { System.out.println("TOSTRING PASS"); } else { System.out.println("TOSTRING FAIL"); } } catch (Exception e) { System.out.println("TOSTRING FAIL"); } //test proper capacity of array if (set.capacity() != 20) { System.out.println("SIMPLE CAPACITY FAIL"); return; } System.out.println("SIMPLE CAPACITY PASS"); for (int i = 0; i < 100; i++) { set.add(new Player((String.valueOf((char) (i + 97))) + i, i)); } if (set.capacity() != 160) { System.out.println("COMPLEX CAPACITY FAIL"); return; } System.out.println("COMPLEX CAPACITY PASS"); } }
In: Computer Science
Consider a metal wire that is used as thermistor. When it is connected to a 10.00 V voltage source, at 23.50C a current of 0.4212 A is flowing through the wire. What will the temperature if the current is 0.3818 A. Assume a = 0.00429 (C0)-1
In: Physics
What information do you need to determine the yield of a coupon bond? 28) ______
I) Bond price
II) Coupon rate
III) Par value
IV) Maturity date
V) Yield curve.
In: Finance
If velocity (V) and aggregate output (Y) remain constant at $4 and $1,250 billion, respectively, what happens to the price level (P) if the money supply (M) declines from $475 billion to $375 billion?
In: Economics
A drug for injection is supplied as a vial has a concentration of 5% w/v. 10 mL of this vial is injected into an infusion bag to make a final volume of 500 mL. What is the concentration of the drug in the infusion bag?
In: Nursing