Question

In: Computer Science

Write a program in Java Using object Orientation Design to determine the status of Mini Van...

Write a program in Java Using object Orientation Design to determine the status of Mini Van Sliding Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door.

  1. A method must be written to indicate the gear shift status and return to main.
  2. A method to display which door is open or can be opened.
  3. A method to show the status of all doors
  4. A method to convert the code to decimal and store in the text file (Character based) as a record.

** MUST USE constructors and methods. The methods should be instantiated by an object. Use simple main. The first bit Stream must be entered by users. The program needs to be interactive

Hints & Suggestions

park

door1

door2

dashboardSwitch

inHandle

outHandle

safteyLock

p d1 d2 dw inh outh sLock desc
1 1 1 1 1 1 0 Saftey Lock Off, door 1 & 2 open
1 1 0 1 1 1 0
1 0 1 1 1 1 0
0 0 0 0 0 0 0 Car not parked, no door works
1 0 0 0 0 1 1 Saftey lock on, door only opens from outside

Solutions

Expert Solution

Solution for the given probem

Please find the code below. Save the file as door.java and change the path of the text file and then run the file door.java .

import java.util.Scanner;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

class Mini_Van_Sliding_Doors

{

boolean child_safety_lock;

boolean master_lock;

String gear_shift;

Mini_Van_Sliding_Doors(boolean child_safety_lock,boolean master_lock, String gear_shift)

{

this.child_safety_lock=child_safety_lock; this.master_lock=master_lock; this.gear_shift=gear_shift;

}

boolean inside_handle()

{

if (child_safety_lock == true || master_lock == true )

{

return false;

}

else

{

return true;

}

}

boolean outside_handle()

{

return true;

}

boolean gear_shift_status()

{

if ( gear_shift =="park")

{

return true;

}

else

{

return false;

}

}

boolean converter (String code)

{

long val = Integer.parseInt(code,2);

if (val == 10)

{

// Validate if the binary code is decimal equivalent to 10 or not . You can change the number as well try

{

FileWriter myWriter = new FileWriter("C:\\Users\\escuhao\\Desktop\\doorcode.txt");

// Path where the code is recorded. myWriter.write("Door code : "+val);

myWriter.close();

System.out.println("Code is recorded for the door . ");

}

catch (IOException e)

{

System.out.println("Alert !!! An exception happens !!!"); e.printStackTrace();

}

return true;

}

else

{

return false;

}

}

void display(boolean dec_code)

{

boolean g_status = gear_shift_status();

boolean in_handle = inside_handle();

boolean out_handle = outside_handle();

if (g_status ==true && out_handle == true && dec_code == true)

{

System.out.println("Door is open or can be opened by outside handle");

if (in_handle == true)

{

System.out.println("Door is open or can be opened by inside handle");

}

}

else { System.out.println("Door is locked");

}

}

}

public class door

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in); System.out.println("Enter the binary code : ");

String code = sc.nextLine();

System.out.println("Status of Door 1: "); Mini_Van_Sliding_Doors door1 = new Mini_Van_Sliding_Doors(false,false,"park");

// child_safety_lock , master_lock are off boolean rn1=door1.converter(code); door1.display(rn1); System.out.println("Status of Door 2: "); Mini_Van_Sliding_Doors door2 = new Mini_Van_Sliding_Doors(false,true,"park");

// child_safety_lock is on but master_lock is off boolean rn2=door2.converter(code); door2.display(rn2);

System.out.println("Status of Door 3: "); Mini_Van_Sliding_Doors door3 = new Mini_Van_Sliding_Doors(true,true,"park");

// child_safety_lock , master_lock are on boolean rn3=door3.converter(code); door3.display(rn3); System.out.println("Status of Door 4: "); Mini_Van_Sliding_Doors door4 = new Mini_Van_Sliding_Doors(true,true,"nopark");

// gear_status is not "park" boolean rn4=door4.converter(code);

door4.display(rn4);

}

}

Out Put :

*********Thank You*********


Related Solutions

Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door. A method must be...
Write a program in Java Using object Orientation Design to determine the status of Mini Van...
Write a program in Java Using object Orientation Design to determine the status of Mini Van Sliding Doors. A logical circuit receives a different binary code to allow opening different doors. The doors can be opened by a dashboard switch, inside or outside handle. The inside handle will not open the door if the child safety lock is on or the master lock is on. The gear shift must be in the park to open the door. A method must...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse...
Write a Java Program to determine if a candidate qualifies for a FHA Mortgage. (using eclipse IDE) The qualifications given are: Residence: The home must be your primary residence. Down payment: They must have a credit score of at least 563. The Java Program needs to do the following. This can all be done in the main() method. Create a boolean variable to store the Residence requirement. Prompt the user to "Enter 1 if the Home will be the primary...
Problem Write a movie management system using object-oriented design principles. The program will read from the...
Problem Write a movie management system using object-oriented design principles. The program will read from the supplied data file into a single array list. The data file (movies.txt) contains information about the movies. Each movie record has the following attributes: - Duration (in minutes) - Title - Year of release Each record in the movies.txt file is formatted as follows: - Duration,Title,Year - e.g.: 91,Gravity,2013 Specifically, you have to create an interactive menu driven application that gives the user the...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
Write a java program using the information given Design a class named Pet, which should have...
Write a java program using the information given Design a class named Pet, which should have the following fields (i.e. instance variables):  name - The name field holds the name of a pet (a String type)  type - The type field holds the type of animal that a pet is (a String type). Example values are “Dog”, “Cat”, and “Bird”.  age - The age field holds the pet’s age (an int type) Include accessor methods (i.e. get...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT