Question

Language : JAVA Part A Create a class CompanyDoc, representing an official document used by a...

Language : JAVA

Part A

Create a class CompanyDoc, representing an official document used by a company. Give it a String title and an int length.

Throughout the class, use the this. notation rather than bare instance variables and method calls.  

Add a default constructor.

Add a parameterized constructor that takes a value for title. Use this( appropriately to call one constructor from another.


Add a toString(), which returns a string with the title, and the length in parentheses. So it might look like:

Employment Turnover Report (16342) 

Add a method longer( with return type boolean, which takes a CompanyDoc as parameter.

doc1.longer(doc2) returns true if doc1's length is greater than doc2's length, false otherwise.

Part B
Create a class Employee with an instance variable for name and instance variable currentDoc of type CompanyDoc.

To CompanyDoc, also add an instance variable author of type Employee.

In Employee, in the mutator for currentDoc, make sure that when a CompanyDoc becomes an employee's currentDoc, the employee becomes the author of the document as well.

In Employee, add a method swapDocs( which takes another Employee and has them swap their currentDocs.

Part C

Create a class DocRepository with one instance variable of type Employee, currentEmployee

Add a method menu that presents a menu-driven interface as follows (you can add as many methods to do this as you like ):

Main menu -- user can either create an employee or end the program

If they create an employee, ask for the name, create an employee with that name (henceforth, the current employee) , and go to Employee Menu. (Do this even if a current employee was created previously; just replace the old one.)

Employee menu -- user can create a document, edit document, view document, or return to the main menu.

If they ask to create a document, what we want to do is ask for the title, create that document, and make it the current employee's current document.  First, however, check whether the current employee already has a current document. If not, just go ahead. If they have one, first ask if they want to replace it, and only do so if they say yes. After this, return to the Employee Menu

If they edit the document, first check if the current employee has a document. If not, complain and return to the Employee menu. If so, go to the Document menu.

If they view the document, simply print the current document.

Document menu -- user can add words, remove words, or return to the Employee menu.

If the user adds words, ask how many, and add that to the length of the current document.

If the user removes words, check that there are at least that many words in the current document. If so, subtract that from the length, otherwise complain and return to the Document menu.

In a separate main, create a DocRepository and have it start its menu.

[EC+15]

In another class with a main SongSwitch in your project, do problem 5.29 from the text (book: Java How to Program (Early Objects)) for printing a cumulative song using loops and switch statements. However, instead of 12 Days of Xmas, do some other similar song, like Old Lady Who Swallowed the Fly, Hole in the Bottom of the Sea, or I Had a Shoggoth (or one you make up yourself).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

import java.util.Scanner; //imported Scanner class

class CompanyDoc{ //CompanyDoc class implementation.

//instance variables

private String title;

private int length;

private Employee author;

//constructors.

public CompanyDoc(){

this.title = null;

this.length = 0;

}

public CompanyDoc(String title){

this.title = title;

this.length = 0;

}

public CompanyDoc(String title, int length){

this.title = title;

this.length = length;

}

//toString method.

public String toString(){

return this.title+" ("+this.length+")";

}

//longer method.

public boolean longer(CompanyDoc cd){

if(this.length>cd.length)

return true;

return false;

}

//menu method, not implemented as not stated in question.

public void menu(){

}

}

class Employee{//Employee class.

//instance variables.

private String name;

private CompanyDoc currentDoc;

//constructors

public Employee(){

this.name=null;

this.currentDoc=null;

}

public Employee(String name){

this.name = name;

this.currentDoc = null;

}

public Employee(String name, CompanyDoc currentDoc){

this.name = name;

this.currentDoc = currentDoc;

}

//setter for currentDoc

public void setCurrentDoc(CompanyDoc currentDoc){

this.currentDoc = currentDoc;

}

//getter for currentDoc

public CompanyDoc getCurrentDoc(){

return this.currentDoc;

}

//swapDocs method.

public void swapDocs(Employee e){

CompanyDoc cd = e.getCurrentDoc();

e.setCurrentDoc(this.currentDoc);

this.currentDoc = cd;

}

//menu method

public void menu(){

Scanner scanner = new Scanner(System.in);

System.out.print("\n1.create Document\n2.edit Document\n3.view Document\nAny other option to return to main menu\nenter option: ");

int option = scanner.nextInt();

if(option==1){

if(this.getCurrentDoc()!=null){

System.out.print("The current Employee already has a document. Do you want to replace it (yes|no): ");

scanner.nextLine();

String choice = scanner.nextLine();

if(choice.toUpperCase().equals("YES")){

System.out.print("Enter title: ");

String title = scanner.nextLine();

CompanyDoc cd = new CompanyDoc(title);

this.setCurrentDoc(cd);

}

}

else{

System.out.print("Enter title: ");

scanner.nextLine();

String title = scanner.nextLine();

CompanyDoc cd = new CompanyDoc(title);

this.setCurrentDoc(cd);

}

this.menu();

}

else if(option==2){

if(this.getCurrentDoc()!=null){

this.currentDoc.menu();

}

else{

System.out.println("The current Employee has no document");

this.menu();

}

}

else if(option==3){

System.out.println(this.currentDoc);

this.menu();

}

else return;

}

}

class DocRepository{ //DocRepository class which is used as driver class in this program

//instance variable.

private Employee currentEmployee;

//menu method.

public void menu(){

System.out.print("\n1. create Employee\nAny other number to end program\nenter option: ");

}

public static void main(String[] args) { //main method

DocRepository dr = new DocRepository(); //object created for DocRepository class

Scanner scanner = new Scanner(System.in);//object created for Scanner class.

dr.menu();//called menu method of DocRepository class.

int option = scanner.nextInt();

while(option==1){

System.out.print("Enter Employee name: ");

scanner.nextLine();

String name = scanner.nextLine();

dr.currentEmployee = new Employee(name);

dr.currentEmployee.menu();

dr.menu();

option = scanner.nextInt();

}

}

}

//output screenshots

Add a comment
Know the answer?
Add Answer to:
Language : JAVA Part A Create a class CompanyDoc, representing an official document used by a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java language (a) Create a class HexEditor with a constructor which creates a 5x10 text area...

    Java language (a) Create a class HexEditor with a constructor which creates a 5x10 text area in a Frame. Also add a pull-down menu with a menu item "Load". Copy the class as the answer to this part. (b) Create another class TestHexEditor with a main() method which creates an object anEditor of the class HexEditor and displays the frame in part (a) using setVisible(true). Copy the class as the answer to this part. (c) Make changes to the class...

  • Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

    Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter...

  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  • Go to the Java API and review the Rectangle class briefly. As directed below, create a...

    Go to the Java API and review the Rectangle class briefly. As directed below, create a subclass of the Rectangle class called BetterRectangle as described below. Create another class called RectangleTester, which fully tests the BetterRectangle, by displaying a menu that allows a user to process data for multiple rectangles until they choose to quit. Be sure to include sample runs as block comments in your tester source code file. P9.10 The Rectangle class of the standard Java library does...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Create a class Circle with one instance variable of type double called radius. Then define an...

    Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming...

    (Java with Netbeans) Programming. Please show modified programming code for already given Main class, and programming for code for the new GameChanger class. // the code for Main class for step number 6 has already been given, please show modified progrraming for Main class and GameCHanger class, thank you. package .games; import java.util.Random; import java.util.Scanner; public class Main { public static void main(String args[]) { System.out.println("Welcome to the Number Guessing Game"); System.out.println(); Scanner sc = new Scanner(System.in); // Get upper...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • (1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2)...

    (1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2) Build the Song class in Song.java with the following specifications: Private fields String songTitle String songArtist int secDuration Initialize String fields to "Not defined" and numeric to 0. Create overloaded constructor to allow passing of 1 argument (title), 2 (title, artist) and 3 arguments (title, artist, duration). Create public member method printSongInfo () with output formatted as below: Title: Born in the USA Artist:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT