Sign In
Not register? Register Now!
You are here: HomeCourseworkTechnology
Pages:
2 pages/≈550 words
Sources:
Level:
APA
Subject:
Technology
Type:
Coursework
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 12.96
Topic:

Introduction to java programming (Coursework Sample)

Instructions:

Primary Task Response: Within the Discussion Board area, write 400–600 words that respond to the following questions with your thoughts, ideas, and comments. This will be the foundation for future discussions by your classmates. Be substantive and clear, and use examples to reinforce your ideas: Your technical leader has submitted additional requirements for your application. You have been asked to enhance the application so that it includes data validation, computes average sales data, and computes average shipping charges. To plan for this new functionality, you will define 2 new method headers and develop pseudocode. Data Validation Requirement To incorporate data validation at the time of product data entry, you will need to include an error-checking condition to allow the user to reenter a data value that is not valid. For example, if a class should have a positive number for an attribute, continuously prompt the user for a valid positive number until one has been entered by the user. Based on the attributes you provided, you will select where to include appropriate error checking. You must include error checking for at least one value required by the user. Provide pseudocode that includes error checking. New Methods Define method headers for computeAverageSales() and computeShipping Charges() according to the following requirements. Develop pseudocode for two new methods to be added to your product class: The computeAverageSales() method should use sentinel-controlled repetition to allow a user to enter product sales data until the user has indicated that he or she is done. The average of the entered sales data will be computed and returned by the method to be displayed by the application. For example, if the user entered 500.50, 250.50, and 300.30, then the average sales would be computed for these 3 values and returned by the method. The prompting of the sales data is done within the method. If the value of the average sales exceeds, $200.00, a message should be displayed to alert the user that the product has produced a significant amount of revenue. The computeAverageSales() method should return type "double." The computeShippingCharges() method should use sentinel-controlled repetition to allow a user to enter shipping data until the user has indicated that he or she is done. The total shipping charges will be computed and returned as a double value. Post your pseudocode for the data validation, method headers, and pseudocode for each new method to the Discussion Board. You will use your pseudocode to make the modifications to your application in an upcoming task.

source..
Content:
Introduction to java programming
Data validation requirement
First we define the code for entering data which is as displayed as below.
package newmethods;
import java.beans.*;
// good for doing the data validations
import java.io.*
//reading data streams
public class BusinesObject {
public static void main(String[] args) {
// TODO Auto-generated method stub
class BusinessObject {
private int numericValue;
public void setNumericValue(int newNumericValue) {
numericValue = newNumericValue;
}
public int getNumericValue() {

return numericValue;
}
}
}
}
Code for data validation
We will use the constraint object code which is used to delegate an object data entry. It will also assign the validation responsibilities to a component called the link validator. The code is as displayed below:
package newmethods;
public class ConstraintObject {
public static void main(String[] args) {
// TODO Auto-generated method stub
public class ConstrainedObject {
private VetoableChangeSupport vetoableSupport = new VetoableChangeSupport(this);
/**
* this will create a new object with generic property validator
*/
public ConstrainedObject() {
vetoableSupport.addVetoableChangeListener(new Validator());
}
protected void validate(String propertyName, int oldValue, int newValue) throws PropertyVetoException {
vetoableSupport.fireVetoableChange(propertyName, new Integer(oldValue), new Integer(newValue));
}
}
}
}
We will then be required to integrate the two classes of code. To intergrate the two modules of the application. The following code will be used. This will then validate the data and give a go ahead for data entry and storage in the database.
public class BusinessObject extends ConstrainedObject {
private int numericValue;
public void setNumericValue(int newNumericValue) throws PropertyVetoException {
// validate proposed value
validate("numericValue", numericValue, newNumericValue);
// the new value is approved, since no exceptions were thrown
numericValue = newNumericValue;
}
public int getNumericValue() {
return numericValue;
}
public class Validator implements VetoableChangeListener {
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
// you will do the validation here
}
}
We are then required to create a code that reads the data in the database and give calculations of average sales and the shipping sales.
The code for calculating average sales in as written below.
package newmethods;
public class culculate {
public static void main(String[] args) {
// TODO Auto-generated method stub
package org.myorg;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.util.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class calcAll {
public static class Map extends MapReduceBase implements Mapper {
public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) throws IOException {
// this will work even if we receive more than 1 line
Scanner scanner = new Scanner(value.toString());
String line;
String[] tokens;
double observation;
while (scanner.hasNext()) {
line = scanner.nextLine();
tokens = line.split("\\s+");
observation = Double.parseDouble(tokens[1]);
output.collect(new Text("values"), new DoubleWritable(observation));
}
}
}
public static class Combine extends MapReduceBase implements Reducer {
public void reduce(Text key, Iterator values, OutputCollector output, Reporter reporter) throws IOException {
double count = 0d; // should be an int, but anyway...
double sum = 0d;

double value;
while (values.hasNext()) {
++count;
value = values.next().get();
sum += value;
}
// keep in alphabetical order or KABOOM!
...
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:

Other Topics:

Need a Custom Essay Written?
First time 15% Discount!