Solved by Expert Tutors
Solved by Expert Tutors
Question

I have these two assignments about Java programming. I have got codes

for them but they does not seem to work. I will attach both assignment plus my code. You can either do it by fixing my code for them to run or do it from scratch with your own code. Please i need SCREENSHOT and some explanation for this assignment to be complete.

public class HeadPhones { public static final int LOW = 1; public static final int MEDIUM = 2; public static final int HIGH = 3; private int volume = MEDIUM; private boolean pluggedIn = false; private String manufacturer; private String headPhoneColor; /** * Default Constructor */ public HeadPhones() { } /*** * Change the voulme * @param value */ public void changeVolume(int value) { setVolume(value); } /** * Return Description of Object */ public String toString() { return "Volume: " + getVolume() + "\n" + "Plugin is set: " + isPluggedIn() + "\n" + "Color of HeadePhone: " + getHeadPhoneColor() + "\n" + "Manufacturer: " + getManufacturer(); } /** * Set volume * @param volume */ public void setVolume(int volume) { this.volume = volume; } /*** * Get Volume * @return volume */ public int getVolume() { return volume; } /** * Set plugin * @param pluggedIn */ public void setPluggedIn(boolean pluggedIn) { this.pluggedIn = pluggedIn; } /*** * Get Plugin is true or false * @return pluggedIn */ public boolean isPluggedIn() {
Background image of page 1
return pluggedIn; } /*** * Set Manufacture * @param manufacturer */ public void setManufacturer(String manufacturer) { this.manufacturer = manufacturer; } /*** * Get Manufacture * @return manufacturer */ public String getManufacturer() { return manufacturer; } /*** * Set the Color * @param headPhoneColor */ public void setHeadPhoneColor(String headPhoneColor) { this.headPhoneColor = headPhoneColor; } /** * This method will return the color * @return headPhoneColor */ public String getHeadPhoneColor() { return headPhoneColor; } }
Background image of page 2
1 Homework 2 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Design a Java class named Polygon that contains: A private int data field named numSides that defines the number of sides of the polygon. The default value should be 4. A private double data field named sideLength that defines the length of each side. The default value should be 5.0. A private double data field named xCoord that defines the x-coordinate of the center of the polygon. The default value should be 0.0. A private double data field named yCoord that defines the y-coordinate of the center of the polygon. The default value should be 0.0. A private double data field named apothem that defines the apothem of the polygon. The default value should 5.0. A private double data filed named perimeter that defines the perimeter of the polygon. The default value should 20.0. A no argument constructor that creates a Polygon using the default number of sides, default side length, default x- and y-coordinates, and the default apothem. A constructor that creates a Polygon using a specified number of sides, side length, x- and y-coordinates and the apothem Getter and setter methods for all data fields A getArea() method that returns a double value representing the area of the polygon. (Note the area of a regular Polgon can be calculated from ½ * Apothem*Perimeter) A toString() method that displays the number of sides, side length, x-coordinate, y- coordinate and apothem values in String format Be sure your code compiles. You should use the command prompt and not a GUI for data entry and display. Write a Java test program, named TestPolygon, to create 5 different polygons representing the 5 test cases you just created. When creating the five polygons, create one using the no argument constructor. For the remaining four, feel free to use any number of sides, side length and x-, and y-coordinates and apothem that are not equal to the default values and not equal to each other. For each of the five polygons, call all of the methods and display the results. For example for a Polygon with 3 sides, side length of 2.0 and x-coordinate and y-coordinates of 1.0, and apothem of 1.0 the following test data may result: ***Output*** toString(): (numsides=3, sideLength=2.0, xcoord=1.0,ycoord=1.0, apothem=1.0) getNumSides(): 3 getSideLength(): 2.0 getXCoord(): 1.0 getYCoord(): 1.0 getApothem():1.0 getPerimeter(): 6.0
Background image of page 1
2 getArea(): 3.0 Document your test cases in the form of table with columns indicating the input values, expected output, actual output and if the test case passed or failed. This table should contain 4 columns with appropriate labels and a row for each test case. An example template is shown below. Note that the actual output should be the actual results you receive when running your program and applying the input for the test record. Keep in mind, for five Polygons, you will have five different output results. Also, note there is no requirement to actually draw a Polygon. Example test cases: Input Expected Output Actual Output Pass? Constructor: numsides=3 sideLength=2.0 xcoord=1.0 ycoord=1.0 apothem=1.0 ** Output ** toString(): (numsides=3, sideLength=2.0, xcoord=1.0,ycoord=1.0, apothem=1.0) getNumSides(): 3 getSideLength(): 2.0 getXCoord(): 1.0 getYCoord(): 1.0 getApothem():1.0 getPerimeter(): 6.0 getArea(): 3.0 ** Output ** toString(): (numsides=3, sideLength=2.0, xcoord=1.0,ycoord=1.0, apothem=1.0) getNumSides(): 3 getSideLength(): 2.0 getXCoord(): 1.0 getYCoord(): 1.0 getApothem():1.0 getPerimeter(): 6.0 getArea(): 3.0 Yes Test case 2 here Test case 3 here Test case 4 here Test case 5 here The google recommended Java style guide, provided as link in the week 2 content, should be used to format and document your code. Specifically, the following style guide attributes should be addressed: Header comments include filename, author, date and brief purpose of the program. In-line comments used to describe major functionality of the code. Meaningful variable names and prompts applied. Class names are written in UpperCamelCase. Variable names are written in lowerCamelCase. Constant names are in written in All Capitals. Braces use K&R style .
Background image of page 2
Show entire document
Homework 4 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Write a Java program the displays the State bird and flower. You should use your IDE for this exercise . You should also use Java classes to their full extent to include multiple methods and at least two classes. The program should prompt the user to enter a State and print both the State bird and flower. The user should be able to enter a State without worrying about case. (e.g. Users could enter Maryland, maryland, MARYLAND or any other possible combination of lower and upper case characters. States may also contain leading and trailing white spaces. Hint: Store the State information in a multi- dimensional array. The program should continue to prompt the user to enter a state until “None” is entered. After all States have been entered by the user, the program should display a summary of the results. You will need to do some research to find the State birds and flowers. Here is a sample run: Enter a State or None to exit: Maryland Bird: Baltimore Oriole Flower: Black-eyed Susan Enter a State or None to exit: Delaware Bird: Blue Hen Chicken Flower: Peach Blossom Enter a State or None to exit: None **** Thank you ***** A summary report for each State, Bird, and Flower is: Maryland, Baltimore Oriole, Black-eyed Susan Delaware, Blue Hen Chicken, Peach Blossom Please visit our site again! Create a test class that constructs at least 3 States objects. For each of the objects constructed, demonstrate the use of each of the methods. Be sure to use your IDE to accomplish this assignment. The google recommended Java style guide, provided as link in the week 2 content, should be used to format and document your code. Specifically, the following style guide attributes should be addressed: Header comments include filename, author, date and brief purpose of the program. In-line comments used to describe major functionality of the code. Meaningful variable names and prompts applied. Class names are written in UpperCamelCase. Variable names are written in lowerCamelCase. Constant names are in written in All Capitals. Braces use K&R style .
Background image of page 1
Submission requirements Deliverables include all Java files (.java) and a single word (or PDF) document. The Java files should be named appropriately for your applications. The word (or PDF) document should include screen captures showing the successful compiling and running of each of the test cases. Each screen capture should be properly labeled clearly indicated what the screen capture represents. The test cases table should be included in your word or PDF document and properly labeled as well. Submit your files to the Homework 4 assignment area no later than the due date listed in your LEO classroom. You should include your name and HW4 in your word (or PDF) file submitted (e.g. firstnamelastnamehw4.docx or firstnamelastnamehw4.pdf) Grading Rubric: The following grading rubric will be used to determine your grade: Attribute Meets Does not meet StatesDataEntry Class 10 points The program prompts the user to enter a State and prints both the State bird and flower. State data entry is case insensitive. States data may also contain leading and trailing white spaces. The program continues to prompt the user to enter a state until “None” is entered. After all data has been entered by the user, the program displays a summary report of all state requests. An IDE (Netbeans or Eclipse) was used for this assignment. 0 points The program does not prompt the user to enter a State and prints both the State bird and flower. State data entry for case insensitive input are not handled properly. States data containing leading and trailing white spaces are not handled properly. The program does not continue to prompt the user to enter a state until “None” is entered. After all data has been entered by the user, the program does not display a summary report of all state requests. An IDE (Netbeans or Eclipse) was not used for this assignment. Test StatesDataEntry Class 5 points 0 points
Background image of page 2
Show entire document
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author [email protected] */ public class Polygon { private int numSides; //number of sides private double sideLength; //length of each side private double xCoord; //x-coordinate of th center of the polygon private double yCoord;//the y-coordinate private double apothem;//defines the apothem private double perimeter; /** * no argument constructor */ public Polygon() { this.numSides = 4; this.sideLength = 10.0; this.xCoord = 0.0; this.yCoord = 0.0; this.apothem = 5.0; this.perimeter = 20.0; } /** * constructor that takes arguments * * @param _numSides :-number of sides * @param _sideLength :-the length of each side * @param _xCoord :-the x coordinate * @param _yCoord :-the Y coordinate * @param _apothem :-the apothem */ public Polygon(int _numSides, double _sideLength, double _xCoord, double _yCoord, double _apothem) { this.numSides = _numSides; this.sideLength = _sideLength; this.xCoord = _xCoord; this.yCoord = _yCoord; this.apothem = _apothem; } /** * * @return area of the polygon[double] */ public double getArea() { perimeter = numSides * sideLength; double area = (0.5) * apothem * perimeter; return area; } //getter & setters public int getNumSides() { return numSides;
Background image of page 1
} public void setNumSides(int numSides) { this.numSides = numSides; } public double getSideLength() { return sideLength; } public void setSideLength(double sideLength) { this.sideLength = sideLength; } public double getxCoord() { return xCoord; } public void setxCoord(double xCoord) { this.xCoord = xCoord; } public double getyCoord() { return yCoord; } public void setyCoord(double yCoord) { this.yCoord = yCoord; } public double getApothem() { return apothem; } public void setApothem(double apothem) { this.apothem = apothem; } public double getPerimeter() { return perimeter; } public void setPerimeter(double perimeter) { this.perimeter = perimeter; } //to string method @Override public String toString() { return "Polygon definitions[" + "number of sides=" + numSides + ", Each side length=" + sideLength + ", xCoord=" + xCoord + ", yCoord=" + yCoord + ", apothem=" + apothem + ']'; } }
Background image of page 2
public class TestHeadPhones { /** * @param args */ public static void main(String[] args) { HeadPhones h1 = new HeadPhones(); h1.setVolume(2); h1.setHeadPhoneColor("CYAN"); h1.setManufacturer("Bass"); h1.setPluggedIn(true); HeadPhones h2 = new HeadPhones(); h2.setVolume(1); h2.setHeadPhoneColor("blue"); h2.setManufacturer("Bass"); h2.setPluggedIn(true); HeadPhones h3 = new HeadPhones(); h3.setVolume(HeadPhones.HIGH); h3.setHeadPhoneColor("DARK GRAY"); h3.setManufacturer("Bass"); h3.setPluggedIn(true); // Print description of all headphones System.out.println("Description of Headphone 1"); System.out.println(h1.toString() + "\n"); System.out.println("Description of Headphone 2"); System.out.println(h2.toString() + "\n"); System.out.println("Description of Headphone 3"); System.out.println(h3.toString() + "\n"); //change volume of headphone 1 h1.changeVolume(3); System.out.println("Description of Headphone 1"); System.out.println(h1.toString() + "\n"); } }
Background image of page 1
public class TestPolygon { public static void main(String[] args) { //create Polygon class object with no parameters Polygon poly1 = new Polygon(); //call all methods System.out.println(poly1.toString()); System.out.println("\tNumber of sides: " + poly1.getNumSides() + "\n" + "\tPolygon side length: " + poly1.getSideLength() + "\n" + "\tThe X coordinate: " + poly1.getxCoord() + "\n" + "\tThe Y coordinate: " + poly1.getxCoord() + "\n" + "\tPolygon's apothem: " + poly1.getyCoord() + "\n" + "\tThe polygon perimeter: " + poly1.getPerimeter() + "\n" + "\tThe polygon area: " + poly1.getArea()); ///create 4 Polygon class object with parameters Polygon poly[] = new Polygon[4]; //intialize the objects with values poly[0] = new Polygon(3, 2.0, 1.0, 1.0, 1.0);// [Sides,sideLength,xCoord,yCoord,apothem] poly[1] = new Polygon(8, 7.1, 1.0, 1.0, 5.0); poly[2] = new Polygon(6, 4.1, 0.0, 0.0, 2.0); poly[3] = new Polygon(7, 4.0, 2.0, 2.0, 4.0); //display the values for (int i = 0; i < poly.length; i++) { System.out.println("----------------------------------------"); System.out.println(poly[i].toString()); System.out.println("\tNumber of sides: " + poly[i].getNumSides()); System.out.println("\tPolygon side length: " + poly[i].getSideLength()); System.out.println("\tThe X coordinate: " + poly[i].getxCoord()); System.out.println("\tThe Y coordinate: " + poly[i].getyCoord()); System.out.println("\tPolygon's apothem: " + poly[i].getApothem()); System.out.println("\tThe polygon perimeter: " + poly[i].getPerimeter()); System.out.println("\tThe polygon area: " + poly[i].getArea()); } } }
Background image of page 1
Sign up to view the entire interaction

Step-by-step answer

s ante, dapibus a molestie consequat, ultrices ac

congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui

Answer.zip - Preview not available

Subscribe to view the full answer

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.

  • -

    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
Let our 24/7 Computer Science tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes