Monday, June 1, 2020
Introduction to java programming Coursework - 550 Words
Introduction to java programming (Coursework Sample) Content: Introduction to java programmingData 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 validationsimport java.io.* //reading data streamspublic 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 vetoab leSupport = 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 Mappe r { 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! ...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.