[For Java Programming: Objects Class] Write a Java application program that prompts the user to enter five floating point values from the keyboard (warning: you are not allowed to use arrays or sorting methods in this assignment - will result in zero credit if done!). Have the program display the five floating point values along with the minimum and maximum values, and average of the five values that were entered. Your program should be similar to (have outputted values be displayed with 4 digits of precision after decimal point, in bold underline is what your user types in when they run the program): Enter Value 1: 2.34567 Enter Value 2: 3.45678 Enter Value 3: 1.23456 Enter Value 4: 5.67891 Enter Value 5: 4.56789 The values entered are: 2.3457, 3.4568, 1.2346, 5.6789, 4.5679 The minimum value is 1.2346 and maximum value is 5.6789 The average of these five values are: 3.4568
In: Computer Science
Write a brief explanation of why these commands function as described. 8. Why does `find . -name '*.pdf'` not find "BOOK.PDF" even if that file is in the current working directory? 9. Why does `find . -name 'pdf*'` not find "book.pdf" even if that file is in the current working directory? 10. Why does `find /etc -iname '*conf*'` return both directories and files?
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
Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:
In: Computer Science
Background: introduction to "Wrapper" classes, this is a tool or concept provided in the Java Programming Language that gives us a way to utilize native datatypes as Objects with attributes and methods. A Wrapper class in Java is the type of class which contains or the primitive data types. When a wrapper class is created a new field is created and in that field, we store the primitive data types. It also provides the mechanism to covert primitive into object and object into primitive.Working with collections, we use generally generic ArrayList<Integer> instead of this ArrayList<int>. An integer is wrapper class of int primitive type. We use a Java wrapper class because for generics we need objects, not the primitives."
Problem: Create a Word Counter application, submit WordCounter.java.
Word Counter takes input of a text file name (have a sample file in the same directory as your Word Counter application to we don't have to fully path the file). The output of our Word Counter application is to echo the file name and the number of words contained within the file.
Sample File: Hello.txt:
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
In: Computer Science
Using this code snippet: Answer the following questions
<div id=”mainContent”>
<p>I’m a cool paragraph
<span>
that has some
<span class=”coolClass”>yellow</span>
text
</span>
</p>
<p class=”blue”>
I’m just some blue text
</p>
<p class=”coolClass”> I should be un-touched text </p>
</div>
<div id=”footer”>
<p class=”tagLine”>Copyright © 2014</p>
</div>
1. Write the CSS rule (selector/declaration) to change all elements with a class of ‘blue’ to have blue foreground text. Hint: color
2. Write the CSS rule to change just the span with a class of “coolClass” to have a text color of yellow.
3. Write the CSS rule to change the element with and id of ‘footer’ to have a font size of 12px. Hint: font-size
4. Write the CSS needed to make all paragraphs in the document have a font weight of bold. Hint: font-weight
In: Computer Science
Below are the parallel arrays that track a different attribute of the apples (note that the above chart (Sweet-Tart Chart) doesn't align with the data from the previous lesson):
names = ["McIntosh", "Red Delicious", "Fuji", "Gala", "Ambrosia", "Honeycrisp", "Granny Smith"]
sweetness = [3, 5, 8, 6, 7, 7.5, 1]
tartness = [7, 1, 3, 1, 1, 8, 10]
Step 1: Data Model (parallel arrays to dictionary)
Build a dictionary named apples. The apple dictionary keys will be the names of the apples. The values will be another dictionary. This value dictionary will have two keys: "sweetness" and "tartness". The values for those keys will be the respective values from the sweetness and tartness lists given above. You will build this by defining a variable named apples (see the complex_map example).
This is why dicitionarries are also calleed associative arrays. The arrays need to be kept in order so they can associate the same index with the same corrresoponding value that make holding this kind of data easier.
Step 2: Apple Aid
Now that we have our model, create a function named by_sweetness whose parameter will be a tuple (from apples.items()) The function by_sweetness will return the sweetness value of the incoming tuple. This helper function cannot reference the global variable apples (from step 1).
Create another function by_tartness that is essentially the same as by_sweetness but returns the tartness value of the incoming tuple.
Step 3: Apple Sorting
Write a function called apple_sorting that has two parameters: data (the data model dictionary) and sort_helper (the function used to sort the model). The apple_sorting should use the sorted function to sort the data (e.g. data.items()) with sort_helper. The function returns a list of tuples in order of their sweetness (sweetest apples listed first).
Once done, this should work:
print(apple_sorting(apples, by_sweetness))
In: Computer Science
Provide brief definitions and an example for each of the following.
a. acute care
b. ALOS
c. Chronic disease
d. Data Mart
e. BI
In: Computer Science
Regarding clinician use of the EMR/EHR, when is the best time to access and document into the EMR/EHR? Explain.
In: Computer Science
There are three steps (open, action, close) required for
handling files. You need to write a Python program what executes
each of these three steps. Your program must include:
Extensive comments to ensure explanation of your code (1).
Open a file (file name must include your student number, thus
filexxxxxxxx.txt). (1).
Write the details of the five students (from Question 1 above) to
a file (3).
Close the file. (1)
Then open the file again (1).
Write the contents of the file to display on the screen (3).
In: Computer Science
Taking as a reference a sensor that delivers a reading through a parallel bus at a rate of 12 bits/ms, carry out a program within MARIE's environment that stores the first 50 measurements in memory.
In: Computer Science
UseMath
Write a program called UseMath. It should contain a class called UseMath that contains the method main. The program should ask for a number from the user and then print the information shown in the examples below. Look at the examples below and write your program so it produces the same input/output.
Examples
(the input from the user is in bold face) % java UseMath enter a number: 0 the square root of 0.0 is: 0.0 rounded to the nearest integer: 0 the value of PI is: 3.141592653589793 the value of PI plus your number is: 3.141592653589793 rounded to the nearest integer: 3 the value of E plus your number is: 2.718281828459045 the absolute value of your number is: 0.0 % java UseMath enter a number: 1 the square root of 1.0 is: 1.0 rounded to the nearest integer: 1 the value of PI is: 3.141592653589793 the value of PI plus your number is: 4.141592653589793 rounded to the nearest integer: 4 the value of E plus your number is: 3.718281828459045 the absolute value of your number is: 1.0 % java UseMath enter a number: -1 the square root of -1.0 is: NaN rounded to the nearest integer: 0 the value of PI is: 3.141592653589793 the value of PI plus your number is: 2.141592653589793 rounded to the nearest integer: 2 the value of E plus your number is: 1.718281828459045 the absolute value of your number is: 1.0 % java UseMath enter a number: .5 the square root of 0.5 is: 0.7071067811865476 rounded to the nearest integer: 1 the value of PI is: 3.141592653589793 the value of PI plus your number is: 3.641592653589793 rounded to the nearest integer: 4 the value of E plus your number is: 3.218281828459045 the absolute value of your number is: 0.5 % java UseMath enter a number: .1 the square root of 0.1 is: 0.31622776601683794 rounded to the nearest integer: 0 the value of PI is: 3.141592653589793 the value of PI plus your number is: 3.241592653589793 rounded to the nearest integer: 3 the value of E plus your number is: 2.818281828459045 the absolute value of your number is: 0.1 % java UseMath enter a number: 10 the square root of 10.0 is: 3.1622776601683795 rounded to the nearest integer: 3 the value of PI is: 3.141592653589793 the value of PI plus your number is: 13.141592653589793 rounded to the nearest integer: 13 the value of E plus your number is: 12.718281828459045 the absolute value of your number is: 10.0 %
In: Computer Science
This is a java program
I am trying to figure out how to add a couple methods to a program I am working on.
I need to be able to:
1. Remove elements from a binary tree
2. Print them in breadth first order
Any help would appreciated.
//start BinaryTree class
/**
*
* @author Reilly
* @param <E>
*/
public class BinaryTree {
TreeNode root = null;
TreeNode current, parent;
private int size = 0, counter = 0;
public int getSize() {
return this.size;
}
public boolean insert(int el) {
current = root;
if (current == null) {
root = new TreeNode(el);
} else {
parent = null;
current = root;
while (current != null) {
if (el < current.element) {
parent = current;
current = current.left;
} else if (el > current.element) {
parent = current;
current = current.right;
} else {
return false;
}
}
if (el < parent.element) {
parent.left = new TreeNode(el);
}
if (el > parent.element) {
parent.right = new TreeNode(el);
}
}
this.size++;
return true;
}
public boolean search(int el) {
current = root;
while (current != null) {
if (el < current.element) {
current = current.left;
} else if (el > current.element) {
current = current.right;
} else {
return true;
}
}
return false;
}
public void inorder() {
inorder(root);
System.out.print("\n");
}
public void inorder(TreeNode curRoot) {
if (curRoot == null) {
return;
}
inorder(curRoot.left);
System.out.print(curRoot.element + " ");
inorder(curRoot.right);
}
public void postorder() {
postorder(root);
System.out.print("\n");
}
public void postorder(TreeNode curRoot) {
if (curRoot == null) {
return;
}
postorder(curRoot.left);
postorder(curRoot.right);
System.out.print(curRoot.element + " ");
}
public void getNumberOfLeaves() {
if (oddOrEven(getNumberOfLeaves(root))) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
int getNumberOfLeaves(TreeNode curRoot) {
if (curRoot == null) {
return 0;
}
if (curRoot.left == null && curRoot.right == null) {
return 1;
} else {
return getNumberOfLeaves(curRoot.left) +
getNumberOfLeaves(curRoot.right);
}
}
public boolean oddOrEven(int x) {
return (x % 2) == 0;
}
}
//start Driver class
public class Driver {
public static void main(String[] args) {
BinaryTree tree = new BinaryTree();
tree.insert(10);
tree.insert(5);
tree.insert(15);
tree.insert(6);
tree.insert(4);
tree.insert(20);
tree.inorder();
tree.getNumberOfLeaves();
tree.inorder();
}
}
//start TreeNode class
public class TreeNode {
int element;
TreeNode left;
TreeNode right;
public TreeNode(int el)
{
this.element = el;
}
}
In: Computer Science
The five key activities in an object-oriented design process are:
a. Define the context and modes of use of the system;
b. Design the system architecture;
c. Identify the principal system objects;
d. Develop design models;
e. Specify object interfaces.
Please give me an explanation and example in detail for the five activities.
In: Computer Science
The language is C++
Below are a list of sequences of numbers. Your job is to program each sequence with any loop of your preference (while, for, do/while). I want the code to output the sequence provided and the next number in the sequence (you can output more but there is 1 sequence that may only have 1 number after).. Please order and notate each sequence in your output –. The output should also be horizontal like that shown below (if you output it vertically it will be -10pts). Each sequence should be programed with only 1 loop and optionally 1 selection statement. Hint: a selection statement may be used for the last 3 problems.
Series 1:
15, 14, 13, 12, 11, ...
Series 2:
1, 2, 5, 14, 41, ...
Series 3:
2, 3, 5, 8, 12, 17, ...
Series 4:
15, 13, 11, 9, 7, ...
Series 5:
71, 142, 283, 564, 1125, 2246, 4487, 8968, ...
Series 6:
10, 5, 1, -2, -4, -5, -5, -4, -2, ...
Series 7:
0, 1, 3, 7, 15, 31, 63, ...
Series 8:
0, 1, 4, 13, 40, 121, ...
Series 9:
15, 29, 56, 108, 208, 400…
series 10: (finite)
0, 1, 3, 6, 10, 10, 11, 13, 16, 16, 17, 19, 19, ...
series 11:
7, 9, 14, 20, 27, 33, 42, 52, 63, 73, 86, ...
Series 12:
13, -21, 34, -55, 89 ...
Series 13:
0, 1, 4, 12, 32, 80, 192, ...
In: Computer Science