Design-and-implement-your-own-java-class-to-represent-a-household-item-computer-science-help

Design and implement your own class to represent a household item of your choice (toaster, pressure cooker, hair dryer, piano …) Your class should have a constructor, one additional method and at least one member variable (e.g. boolean isOn to turn the item on or off). Be sure you demonstrate your class works properly by constructing an instance of it and calling your method. 

Something along this lines….:

// Import statements

import java.util.Scanner;

public class Running {

    public static void main(String[] args){

// Use the Scanner class to input data

Scanner scannerIn = new Scanner(System.in);

// Create object using constructor //

   Treadmill runner = new Treadmill(“Speedy”);

// declare variables //

String errorMessage=””;

char toRun=’y’;

char turnOn=’y’;

int speed=0;

int runTime=0;

boolean isOn=false;

//End declare variables //

// Begin User Prompts //

System.out.print(“33[H33[2J”); //Clear the screen

System.out.println(“”);System.out.println(“”);System.out.println(“”);

while(toRun == ‘y’) {

   toRun=’z’;

errorMessage=””;

while(toRun != ‘y’ && toRun != ‘n’) { //prompt to run

System.out.print(errorMessage+”Do you wish to run on the treadmill? (Y or y for yes, N or n for no): “);

toRun = Character.toLowerCase(scannerIn.next(“.”).charAt(0));

errorMessage=”rn*** Invalid Input!  Please try again.rn”;

}

if(toRun == ‘y’){ //User chose to play

speed=0;

errorMessage=””;

System.out.print(“33[H33[2J”); //Clear the screen

System.out.println(“”);System.out.println(“”);System.out.println(“”);

while(!(speed > 0 && speed < 13)) { //Prompt for run speed

System.out.print(errorMessage+”What speed would you like to run at? (1-12): “);

speed = scannerIn.nextInt();

errorMessage=”rn*** Invalid Input!  Please try again.rn”;

}

runTime=-1;

errorMessage=””;

System.out.print(“33[H33[2J”); //Clear the screen

System.out.println(“”);System.out.println(“”);System.out.println(“”);

while(!(runTime > 0 && runTime < 61)) { //Prompt for run time

System.out.print(errorMessage+”How many minutes would you like to run? (1-60): “);

runTime = scannerIn.nextInt();

errorMessage=”rn*** Invalid Input!  Please try again.rn”;

}

if(!isOn){

turnOn=’z’;

errorMessage=””;

System.out.print(“33[H33[2J”); //Clear the screen

System.out.println(“”);System.out.println(“”);System.out.println(“”);

while(turnOn != ‘y’ && turnOn != ‘n’) { //prompt to turn on treadmill

System.out.print(errorMessage+”The treadmill is turned off.  Do you wish to turn it on? (Y or y for yes, N or n for no): “);

turnOn = Character.toLowerCase(scannerIn.next(“.”).charAt(0));

errorMessage=”rn*** Invalid Input!  Please try again.rn”;

}

}

if(turnOn==’y’)isOn=true;

}

if(isOn){

runner.setTime(runTime);

runner.setSpeed(speed);

runner.run();

}

}

System.out.print(“33[H33[2J”); //Clear the screen

System.out.println(“”);System.out.println(“”);System.out.println(“”);

System.out.println(“I hope you enjoyed your workout!!!”);

}

}

 
Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.