Main Program:import java.util.Scanner;public class ReadingMainExtNew { static ReadingExtNew[] readings = new ReadingExtNew[50]; static int numOfReadings = 0; public static void main(String args[]) { bulkAdd();// to call reading method and display the menu in console } // this method is for add reading to the readings array private static void bulkAdd() { String annotation = null; int readingId = 0; double value = 0; ReadingExtNew reading; boolean valid = false; Scanner in = new Scanner(System.in); while (!valid) { System.out.println("Enter annotation: "); annotation = in.next(); valid = annotation.length() >= 15; if (!valid) { System.out.println("Please enter annotation with minimum 15 characters"); } } valid = false; while (!valid) { try { System.out.println("Enter reading Id: "); readingId = in.nextInt(); valid = true; } catch (Exception e) { System.out.println("please enter number"); in.next(); } } valid = false; while (!valid) { try { System.out.println("Enter value: "); value = in.nextDouble(); valid = true; } catch (Exception e) { System.out.println("please enter number"); in.next(); } } reading = new ReadingExtNew(annotation, readingId, value); readings[numOfReadings] = reading; numOfReadings++; System.out.println(reading); addMenu(); } // this is method is for calculate average value of all readings in readings // array private static void averageReading(ReadingExtNew[] readings, int numOfReadings) { double sum = 0.0; double avg = 0.0; for (int i = 0; i < numOfReadings; i++) { ReadingExtNew reading = readings[i]; sum = sum + reading.getValue(); if (numOfReadings > 0) { avg = sum / numOfReadings; // to calculate average value of readings } } System.out.println("avg " + avg); menu(); }// this method is for display all records in readings Array private static void displayAllReadings() { for (int i = 0; i < numOfReadings; i++) { ReadingExtNew reading = readings[i]; System.out.println(reading); } menu(); } // this method is for display all the Reading records in readings array private static void displayLargestReading() { int largestReadingIndex = 0; ReadingExtNew largestReading = null; for (int i = 0; i < numOfReadings; i++) { largestReading = readings[largestReadingIndex]; if (readings[i].getValue() > largestReading.getValue()) { largestReadingIndex = i; } } largestReading = readings[largestReadingIndex]; System.out.println(largestReading); menu(); } private static void addMenu() { System.out.println(""); boolean valid = false; int option = 0; Scanner in = new Scanner(System.in); // to read user entered data from console System.out.println("MENU SELECTION"); System.out.println("Options:"); System.out.println("1. Add another reading"); System.out.println("2. Menu"); System.out.println("3. Quit"); System.out.println(""); while (!valid) { // validate the user input try { System.out.println("Enter Selection: "); option = in.nextInt(); // to read user entered Selection from console valid = true; } catch (Exception e) { System.out.println("please enter number"); in.next(); } } // Switch construct switch (option) { case 1: bulkAdd(); // to call addReading method break; case 2: menu(); break; case 3: System.out.println("Exit"); in.close(); System.exit(0); // to exit from menu break; default: System.out.println("Invalid selection"); menu(); break; } System.out.println("n n"); } // this method is for display menu and based on menu selection it will give call // the methods to add,display,and calculate average of all records and show the // Reading with highest value private static void menu() { System.out.println(""); boolean valid = false; int option = 0; Scanner in = new Scanner(System.in); // to read user entered data from console System.out.println("MENU SELECTION"); System.out.println("Options:"); System.out.println("1. Add another reading"); System.out.println("2. Display all readings"); System.out.println("3. Display average reading"); System.out.println("4. Display largest reading"); System.out.println("5. Quit"); System.out.println(""); while (!valid) { // validate the user input try { System.out.println("Enter Selection: "); option = in.nextInt(); // to read user entered Selection from console valid = true; } catch (Exception e) { System.out.println("please enter number"); in.next(); } } // Switch construct switch (option) { case 1: bulkAdd(); // to call addReading method break; case 2: if (numOfReadings == 0) { // to check weather array has records System.out.println("No Readings Found,Please enter readings first"); menu(); } else { displayAllReadings(); // to call displayAllReadings method } break; case 3: if (numOfReadings == 0) { System.out.println("No Readings Found,Please enter readings first"); menu(); } else { averageReading(readings, numOfReadings); // to call averageReading method } break; case 4: if (numOfReadings == 0) { System.out.println("No Readings Found,Please enter readings first"); } else { displayLargestReading(); // to call displayLargestReading method } break; case 5: System.out.println("Exit"); in.close(); System.exit(0); // to exit from menu break; default: System.out.println("Invalid selection"); menu(); break; } System.out.println("n n"); }}Data Type Program:public class ReadingExtNew { private String annotation; private int readingId; private double value; public ReadingExtNew(String annotation, int readingId, double value) { super(); this.annotation = annotation; this.readingId = readingId; this.value = value; } public String getAnnotation() { return annotation; } public void setAnnotation(String annotation) { this.annotation = annotation; } public int getReadingId() { return readingId; } public void setReadingId(int readingId) { this.readingId = readingId; } public double getValue() { return value; } public void setValue(double value) { this.value = value; } @Override public String toString() { String check = readingId == 0 ? " check sensor" : readingId > 100 ? "check reading" : ""; return "#" + readingId + " : " + value + " (" + annotation + ") " + check; }} if you could explain the structure chart
Main Program:
import java.util.Scanner;
public class ReadingMainExtNew {
static ReadingExtNew[] readings = new ReadingExtNew[50];
static int numOfReadings = 0;
public static void main(String args[]) {
bulkAdd();// to call reading method and display the menu in console
}
// this method is for add reading to the readings array
private static void bulkAdd() {
String annotation = null;
int readingId = 0;
double value = 0;
ReadingExtNew reading;
boolean valid = false;
Scanner in = new Scanner(System.in);
while (!valid) {
System.out.println(“Enter annotation: “);
annotation = in.next();
valid = annotation.length() >= 15;
if (!valid) {
System.out.println(“Please enter annotation with minimum 15 characters”);
}
}
valid = false;
while (!valid) {
try {
System.out.println(“Enter reading Id: “);
readingId = in.nextInt();
valid = true;
} catch (Exception e) {
System.out.println(“please enter number”);
in.next();
}
}
valid = false;
while (!valid) {
try {
System.out.println(“Enter value: “);
value = in.nextDouble();
valid = true;
} catch (Exception e) {
System.out.println(“please enter number”);
in.next();
}
}
reading = new ReadingExtNew(annotation, readingId, value);
readings[numOfReadings] = reading;
numOfReadings++;
System.out.println(reading);
addMenu();
}
// this is method is for calculate average value of all readings in readings
// array
private static void averageReading(ReadingExtNew[] readings, int numOfReadings) {
double sum = 0.0;
double avg = 0.0;
for (int i = 0; i < numOfReadings; i++) {
ReadingExtNew reading = readings[i];
sum = sum + reading.getValue();
if (numOfReadings > 0) {
avg = sum / numOfReadings; // to calculate average value of readings
}
}
System.out.println(“avg ” + avg);
menu();
}
// this method is for display all records in readings Array
private static void displayAllReadings() {
for (int i = 0; i < numOfReadings; i++) {
ReadingExtNew reading = readings[i];
System.out.println(reading);
}
menu();
}
// this method is for display all the Reading records in readings array
private static void displayLargestReading() {
int largestReadingIndex = 0;
ReadingExtNew largestReading = null;
for (int i = 0; i < numOfReadings; i++) {
largestReading = readings[largestReadingIndex];
if (readings[i].getValue() > largestReading.getValue()) {
largestReadingIndex = i;
}
}
largestReading = readings[largestReadingIndex];
System.out.println(largestReading);
menu();
}
private static void addMenu() {
System.out.println(“”);
boolean valid = false;
int option = 0;
Scanner in = new Scanner(System.in); // to read user entered data from console
System.out.println(“MENU SELECTION”);
System.out.println(“Options:”);
System.out.println(“1. Add another reading”);
System.out.println(“2. Menu”);
System.out.println(“3. Quit”);
System.out.println(“”);
while (!valid) { // validate the user input
try {
System.out.println(“Enter Selection: “);
option = in.nextInt(); // to read user entered Selection from console
valid = true;
} catch (Exception e) {
System.out.println(“please enter number”);
in.next();
}
}
// Switch construct
switch (option) {
case 1:
bulkAdd(); // to call addReading method
break;
case 2:
menu();
break;
case 3:
System.out.println(“Exit”);
in.close();
System.exit(0); // to exit from menu
break;
default:
System.out.println(“Invalid selection”);
menu();
break;
}
System.out.println(“n n”);
}
// this method is for display menu and based on menu selection it will give call
// the methods to add,display,and calculate average of all records and show the
// Reading with highest value
private static void menu() {
System.out.println(“”);
boolean valid = false;
int option = 0;
Scanner in = new Scanner(System.in); // to read user entered data from console
System.out.println(“MENU SELECTION”);
System.out.println(“Options:”);
System.out.println(“1. Add another reading”);
System.out.println(“2. Display all readings”);
System.out.println(“3. Display average reading”);
System.out.println(“4. Display largest reading”);
System.out.println(“5. Quit”);
System.out.println(“”);
while (!valid) { // validate the user input
try {
System.out.println(“Enter Selection: “);
option = in.nextInt(); // to read user entered Selection from console
valid = true;
} catch (Exception e) {
System.out.println(“please enter number”);
in.next();
}
}
// Switch construct
switch (option) {
case 1:
bulkAdd(); // to call addReading method
break;
case 2:
if (numOfReadings == 0) { // to check weather array has records
System.out.println(“No Readings Found,Please enter readings first”);
menu();
} else {
displayAllReadings(); // to call displayAllReadings method
}
break;
case 3:
if (numOfReadings == 0) {
System.out.println(“No Readings Found,Please enter readings first”);
menu();
} else {
averageReading(readings, numOfReadings); // to call averageReading method
}
break;
case 4:
if (numOfReadings == 0) {
System.out.println(“No Readings Found,Please enter readings first”);
} else {
displayLargestReading(); // to call displayLargestReading method
}
break;
case 5:
System.out.println(“Exit”);
in.close();
System.exit(0); // to exit from menu
break;
default:
System.out.println(“Invalid selection”);
menu();
break;
}
System.out.println(“n n”);
}
}
Data Type Program:
public class ReadingExtNew {
private String annotation;
private int readingId;
private double value;
public ReadingExtNew(String annotation, int readingId, double value) {
super();
this.annotation = annotation;
this.readingId = readingId;
this.value = value;
}
public String getAnnotation() {
return annotation;
}
public void setAnnotation(String annotation) {
this.annotation = annotation;
}
public int getReadingId() {
return readingId;
}
public void setReadingId(int readingId) {
this.readingId = readingId;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
@Override
public String toString() {
String check = readingId == 0 ? ” check sensor” : readingId > 100 ? “check reading” : “”;
return “#” + readingId + ” : ” + value + ” (” + annotation + “) ” + check;
}
}
if you could explain the structure chart
Hi there! Click one of our representatives below and we will get back to you as soon as possible.