Im working on modifying my current code to function with these changes below
Create a Java program that meets the following criteria
My current code is show as below, i was wondering how i would go about doing that im a little lost.
import java.io.File;
import java.util.Scanner;
public class Lab5 {
public static void main(String[] args) {
String inFileName;
if (args.length > 1) {
inFileName = args[0];
} else {
Scanner console = new Scanner(System.in);
System.out.println("Enter a Filename: ");
inFileName = console.nextLine();
}
double[] myData = readArray(inFileName);
double[] results = processArray(myData);
// TODO: Display Results...
}
static double[] readArray(String filename) {
File inFile = new File(filename);
if (inFile.canRead()) {
try {
Scanner fileScanner = new Scanner(inFile);
int count = fileScanner.nextInt();
double[] data = new double[count];
for (int i = 0; i < count; i++) {
data[i] = fileScanner.nextDouble();
}
return data;
} catch (Exception e) {
return new double[0];
}
} else {
System.out.println("Can't read file.");
return new double[0];
}
}
static double[] processArray(double[] dataArray) {
// TODO: Implement Functionality from Requirements.
for (double data : dataArray) {
System.out.println(data);
}
return new double[0];
}
}In: Computer Science
Start with a program that allows the user to input a number of integers, and then stores them in an int array.
Write a function called maxint() that goes through the array, element by element, looking for the largest one.The function should take as arguments the address of the array and the number of elements in it, and return the index number of the largest element. The program should call this function and then display the largest element and its index number.
In: Computer Science
Update the following C code and write the function :
void sln_stutter(sln_list* li);
that modifies the list li so that it each element is duplicated. For example the list with elements [1,2,3] would after this function call become the list [1,1,2,2,3,3].
#include <stdlib.h>
#include <stdio.h>
struct sln_node {
struct sln_node* next;
int key;
};
struct sln_list {
struct sln_node* head;
};
typedef struct sln_node sln_node;
typedef struct sln_list sln_list;
static sln_node* freelist = NULL;
/* Internal bookkeeping functions for the free list of nodes. */
sln_node* sln_allocate_node() {
sln_node* n;
if(freelist == NULL) {
freelist = malloc(sizeof(sln_node));
freelist->next = NULL;
}
n = freelist;
freelist = n->next;
n->next = NULL;
return n;
}
void sln_release_node(sln_node* n) {
n->next = freelist;
freelist = n;
}
void sln_release_freelist() {
sln_node* n;
while(freelist != NULL) {
n = freelist;
freelist = freelist->next;
free(n);
}
}
/* Create a new singly-linked list. */
sln_list* sln_create() {
sln_list* list = malloc(sizeof(sln_list));
list->head = NULL;
return list;
}
/* Release the list and all its nodes. */
void sln_release(sln_list* list) {
sln_node* n = list->head;
sln_node* m;
while(n != NULL) {
m = n->next;
sln_release_node(n);
n = m;
}
free(list);
}
/* Insert a new element to the list. */
void sln_insert(sln_list* list, int key) {
sln_node* n = sln_allocate_node();
n->key = key;
n->next = list->head;
list->head = n;
}
/* Check if the list contains the given element. Returns 1 or 0. */
int sln_contains(sln_list* list, int key) {
sln_node* n = list->head;
while(n != NULL && n->key != key) {
n = n->next;
}
return (n == NULL)? 0: 1;
}
/* Remove the first occurrence of the given element from the list.
Returns 1 if an element was removed, 0 otherwise. */
int sln_remove(sln_list* list, int key) {
sln_node* n;
sln_node* m;
n = list->head;
if(n == NULL) { return 0; }
if(n->key == key) {
list->head = n->next;
sln_release_node(n);
return 1;
}
while(n->next != NULL && n->next->key != key) {
n = n->next;
}
if(n->next != NULL) {
m = n->next;
n->next = m->next;
sln_release_node(m);
return 1;
}
return 0;
}
In: Computer Science
I have a list of things for review in C programming, could you please give me an example and a brief explanation for each question... Thank you very much
In: Computer Science
In: Computer Science
Suppose we want to make a 10 item queue starting from location
x4000. In class, we discussed using a HEAD and a TAIL pointer to
keep track of the beginning and end of the queue. In fact, we
suggested that the HEAD pointer could point to the first element
that we would remove from the queue and the TAIL pointer could
point the last element that we have added the queue. It turns out
that our suggestion does not work.
Part a) What is wrong with our suggestion? (Hint: how do we check
if the queue is full? How do we check if it is empty?)
Part b) What simple change could be made to our queue to resolve
this problem?
Part c) Using your correction, write a few instructions that check
if the queue is full. Use R3 for the HEAD pointer and R4 for the
TAIL pointer.
Part d) Using your correction, write a few instructions that check
if the queue is empty. Again, using R3 for the HEAD pointer and R4
for the TAIL pointer.
In: Computer Science
The two-dimensional arrays list1 and list2 are identical if they have the same contents. Write a method that returns true if they are identical and false if they are not. Use the following header: public static boolean equals(int [][] list1, int [][] list2)
Write a test program that prompts the user to enter two 3 x 3 arrays of integers and displays whether the two are identical.
Enter list1:
Enter list2:
The two arrays are identical or The two arrays are not identical
In: Computer Science
Here is a picture of a Binary Search Tree.
First, construct the Binary Search Tree using the following
BinaryNode as we discussed in class.
public class BinaryNode {
private int value;
private BinaryNode leftChild;
private BinaryNode rightChild;
public BinaryNode(int value) {
this.value = value;
leftChild = null;
rightChild = null;
}
public BinaryNode(int value, BinaryNode leftChild, BinaryNode rightChild)
{
this.value = value;
this.leftChild = leftChild;
this.rightChild = rightChild;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public BinaryNode getLeftChild() {
return leftChild;
}
public void setLeftChild(BinaryNode leftChild) {
this.leftChild = leftChild;
}
public BinaryNode getRightChild() {
return rightChild;
}
public void setRightChild(BinaryNode rightChild) {
this.rightChild = rightChild;
}
@Override
public String toString() {
return "BinaryNode: " +
"value=" + value;
}
}
|
Second, print the nodes in level order, that is, the root node first, then the children of the root node, then the grand-children, etc. It is recommended that you accomplish this by using a queue to store the nodes, printing the first nodes that have been added to the queue.
Your program should print the following when it runs.
42 27 50 21 38 60 33 41 72 |
Submit the file LevelOrder.java when done.
In: Computer Science
programming language: JAVA
4. For this question, write code fragments or methods as directed. (a) Create the Point class that depends on a generic data type parameter T. It has two instance variables called xCoordinate and yCoordinate that both have type T. Write a two parameter constructor to initialize the instance variables. Answer: (b) Write a main method that has instructions to perform the following tasks (in order): Declare an ArrayList of Strings called carModels. Add three models. Print the size of the list. Remove the model from index 1. Insert a model at index 0. Replace the model at index 2. Answer: (c) Write a main method with a try-catch block. Inside the block it creates an array of Strings — the array is called list and has size 10. Print the value stored in list[10]. The catch block should catch ArithmeticException and RuntimeException. Your code shouldn’t be longer than 9 lines excluding curly braces. Answer: (d) Write the private method inputCircles that is called by the following main method. As- sume that class Circle exists and has constructors and a toString method. Your method should open a Scanner and obtain a radius for each of the 20 circles that you make from the user. (You should assume that the class Scanner has already been imported.) public static void main(String args[]) { Circle[] data = new Circle[20]; inputCircles(data); for (Circle c:data) System.out.println(c); } Answer:
In: Computer Science
Is there a way to tell the user in the alert how old they are based on their birthday?
<html>
<head>
</head>
<body style="background-color: lightgreen;">
<center><h1>Contact List</h1></center>
<center>
<form>
<label>firstname: </label>
<input type="text" id="firstname">
<br/><br/>
<label>lastname:</label>
<input type="text" id="lastname">
<br/><br/>
<label>birthday:</label>
<input type="date" id="birthday">
<br/><br/>
<label>address:</label>
<textarea id="addr"></textarea>
<br/><br/>
<input type=submit onclick="datacalc()">
</form>
</center>
<script src="script.js">
</script>
</body>
</html>
//function to call when form is submitted
function datacalc(){
//creating and storing the form data into the person object
var person = {
//1. storing each value in respective data components
firstname : document.getElementById('firstname').value,
lastname : document.getElementById('lastname').value,
//3. Storing the date value in birth propertyName
birth : document.getElementById('birthday').value,
addr : document.getElementById('addr').value,
//2. A method to return greetings to the user
greet : function() {
return "Hi "+this.firstname+"... Glad to meet you !\n";
}
};
//calling the greet function and accessing object values of person
alert( person.greet() + "Your birthday is on " + person.birth );
localStorage.setItem('p', JSON.stringify(person)); //to store the object after serializing it. 'p' is just the id to retrieve it back later. stringify() will convert it into serialized form.
var newPerson = JSON.parse(localStorage.getItem('p')); //to retrieve back the serialized object we stored using the id 'p' we assigned to it. parse() will convert it back into the original object.
alert("Your name as stored in storage is " + newPerson.firstname + " " + newPerson.lastname + " and your birth date stored is " + newPerson.birth);
}
In: Computer Science
Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print:
90, 92, 94, 95
Your code's output should end with the last element, without a subsequent comma, space, or newline.
In: Computer Science
Please assist me to choose the right answer
1. You have just completed a clean installation of Windows 7 and have removed the installtion DVD from the drive. When you restart the system you receive the following error message , "Can't find bootable device." which of the following would you do to correct the problem?
a. Reinstall the DVD driver
b. Check Device Manager
c. Change the BIOS boot sequence
d. Look at Event viewer logs
2. Your PC displays the message “No system Disk or Disk Error”. Which of the following will produce this result?
a. The hard drive partition was not activated
b. The system file was not transferred to the hard drive
c. The CMOS lost the hard drive configuration. d. The system was not shut down properly
In: Computer Science
Calculate average test score:
Write a C++ program that calls a function to pass array of test scores of students and calculates the average test scores for each student. Let the user enters 2 students’ test scores for three classes (use two dimensional array). Write another function to pass array of test scores and average to display the test scores for each student and display the average of the test scores for each student as well. So you need to write two functions (one for function to pass array of test scores and average to display the test scores for each student and another for display the average of the test scores for each student as well. ) . You cannot use global variable.
Add version control and write proper comments with a few blank lines & indentations in order to improve your programming style.
Test scores should be between 0-100 (data Validation).
In: Computer Science
LetsVacuum, a family-owned manufacturer of high-end vacuum cleaners, has grown exponentially over the last few years. However, the company is having difficulty preparing for future growth. The only information system used at LetsVacuum is an old accounting system. The company has one manufacturing plant located in Selangor; and three warehouses, in Johore, Kedah, and Trengganu. The LetsVacuum sales force comprises only Malaysian nationals, and the company purchases about 25 percent of its vacuum parts and materials from a single overseas supplier. You have been hired to recommend the information systems LetsVacuum should implement in preparing for future growth.
1. In your own terms,
a. Identify and briefly describe each of the key
business functions of LetsVacuum.
b. Describe an example of the company’s business process either in any of these functional areas or that is cross-functional in nature. Use diagrams whenever possible to support your description.
In: Computer Science
Using C++ and using a boolean variable with local scope to control the looping structure:
How do I create a program that will simulate a game of craps with the below qualification:
Containing two functions -an int rollDice() function that will simulate the rolling of two dice and the main function. When called the roll Dice() function will generate two random numbers between 1 and 6 inclusive, add them, and return the sum as the integer variable “point”. The function will also output the value of the “roll” of each digital die and the value of “point” to cout. Selection and looping structures in the int main() function will determine the impact of each roll (win, lose, or roll again) on the game, print the results, and continue the game if necessary.
In: Computer Science