View the step-by-step solution to:

This program will use a Reading class, which you will create, to store and work with sensor readings. Each Reading has an annotation (a String), a...

This program will use a Reading class, which you will create, to store and work with sensor readings. Each Reading has an annotation (a String), a reading id (an int) and and a value (a double). These become its instance variables.

The program must include the following:

  • In Reading, instance variable declarations, a constructor to initialise their values, getters and setters for each, and a toString method.
  • In the main program, A readReading method that reads in a sensor reading from the user, instantiates a new Reading object using those details and returns that object to the calling code in main(). Before creating the Reading object it must ensure there is a meaningful annotation provided (its length is at least 15), asking the user to re-enter the value while not valid.
  • Reading's toString() method should return a formatted String according to the following pattern, where italicised values refer to those variables in the object: 

  • "#idvalue (annotation)" followed by "check sensor" if the value is 0, or "check reading" if value is larger than 100 

  • For example, a particular Reading object may appear as:
#1138: 0 (my shiny internet-connected toaster) check sensor
  • main() should declare a Reading variable, and then perform the following steps:
  1. Print the message "- Enter Reading Data -"
  2. Use readReading to read in details from the user to instantiate a Reading object, and then store it in the local variable.
  3. Print the message "- You Entered -"
  4. Print the Reading using System.out.println() (it does not need to manually call toString).

import java.util.Scanner;

public class MainProgram {

    //method(s) for reading and validating
    //user input and creating a new DataType

    public static void main(String[] args) {
        Scanner sc = new Scanner(;
        DataType data;

        //calls method to read details from user
        //and assigns result to data

        //displays data using println

public class DataType {
    //variable declarations

    //a constructor

    //getters and setters

    public String toString() {
        //creates and returns a String
        //(does _not_ call println)


Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.


Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question