Free Essay

Unit 4 Assignment

In:

Submitted By coltonjd17
Words 1345
Pages 6
Java Unit 4 Assignment

This is the class needed for questions 1-11.

import java.awt.geom.Rectangle2D;

public class MyRectangleContainer
{
private Rectangle2D.Double containedRectangle; private String nameOfRectangle;

public MyRectangleContainer() { containedRectangle = null; }

public MyRectangleContainer(Rectangle2D.Double rectanglein, String namein) { containedRectangle = rectanglein; nameOfRectangle = namein; }

public void setName(String namein) { nameOfRectangle = namein; }

public void setRectangle(Rectangle2D.Double rectanglein) { containedRectangle = rectanglein; }

public String getName() { return nameOfRectangle; }

public Rectangle2D.Double getRectangle() { return containedRectangle; }
}
This is the beginning of the program needed for questions 1-11.

import java.awt.geom.Rectangle2D;

public class Assignment4RectangleProg
{
public static void main(String[] args) { MyTerminalIO myterminal = new MyTerminalIO();

int x, y, w, h;

myterminal.print("Enter an x value: "); x = myterminal.getInt(); myterminal.print("Enter a y value: "); y = myterminal.getInt(); myterminal.print("Enter a w value: "); w = myterminal.getInt(); myterminal.print("Enter an h value: "); h = myterminal.getInt();

/* Your code would go here. */ }
}

The first 11 questions refer to the code for the MyRectangleContainer class, which is given on the previous page. Questions 1-8 ask you to write lines of code which would follow in a program, the beginning of which is given above. The 8 questions are shown below as they might appear on a test, but without enough room for a handwritten answer. For the assignment the questions are design specifications for work you will do on the computer. What you need to do is hand in a working program that follows these specifications. Compile and debug the program and then run it. Hand in a copy of your finished code and a printout of the output of a test run of the program.

Remember how to make a program and a class work together. You have two choices: 1. Save the MyRectangleContainer class in a file by itself. Also save your program, Assignment4RectangleProg, in a file by itself. Use the usual naming conventions and make sure they’re together in the same directory. 2. It is also possible to put these two pieces of code together in a single file if you want to. Put your program first and the class second in the file. Save the file under the program name, not the class name. Make sure that you change the line of code that declares the class so that it no longer has the key word public in it.

1. Declare and construct an instance of the Rectangle2D.Double class called myrectangle. Use the parameter values already taken in in the program code provided.

2. Write a prompt that will ask the user to enter a name for a Rectangle2D.Double.

3. Take in the the name of the Rectangle2D.Double and store it in myname.

4. Declare and construct an instance of the MyRectangleContainer class using the values myrectangle and myname. Call this instance mycontainer.

5. Write a line of code that would change the nameOfRectangle value stored in mycontainer to Betty Boop.

6. Write a line of code that would change the containedRectangle value stored in mycontainer to the null reference.

7. Write a line of code that would declare a variable called retrievedName and store in it the current value of nameOfRectangle in mycontainer.

8. Write a line of code that would declare a variable called retrievedRectangle and store in it the current value of containedRectangle in mycontainer.

For questions 9 and 10, suppose a program using the MyRectangleContainer class contained the following line of code. Suppose also that no other lines of code do anything with samplecontainer before the questions below.

MyRectangleContainer samplecontainer = new MyRectangleContainer();

9. You don’t have to write down the exact output, but accurately describe the effect or output of executing the following code if it came after the code shown above. Write your answer in the space provided.

Rectangle samplerect = samplecontainer.getRectangle(); myterminal.println(samplerect); 10. You don’t have to write down the exact output, but accurately describe the effect or output of executing the following code if it came after the code shown above. Write your answer in the space provided.

String samplename = samplecontainer.getName(); myterminal.println(samplename); 11. This question is independent of 9 and 10. You don’t have to write down the exact output, but accurately describe the effect or output of executing the following code.

MyRectangleContainer sampletwo; myterminal.println(sampletwo); Questions 12-20 together would form a complete class definition. Please provide the parts asked for in each question. The 9 questions are shown below as they might appear on a test, but without enough room for a handwritten answer. That is because on the assignment the questions are like design specifications. What you have to hand in for this part of the assignment is a printout of the class that you have entered, compiled, and debugged on the computer.

12. The class should have the name MySquare. (Note that MySquare doesn’t have anything to do with the system supplied Rectangle class.)

13. The class should have 2 instance variables, a double called sidelength and a String called hue. (Note that hue doesn’t have anything to do with the system supplied Color class.)

14. Write a constructor that has no parameters. The easier way to do the implementation is to let the system do default initialization. You may also explicitly initialize the instance variables to suitable default values.

15. Write a constructor that takes 2 parameters, one for sidelength and one for hue.

16. Write a method called setLength() that will set the value of the sidelength instance variable.

17. Write a method called setHue() that will set the value of the hue instance variable.

18. Write a method called getLength() that will get the value of the sidelength instance variable.

19. Write a method called getHue() that will get the value of the hue instance variable.

20. Write a method called getArea() that would return the the area of an instance of MySquare by squaring the value contained in the sidelength instance variable.

Another set of problems is starting here. You will notice that this set of problems has the following characteristics:

a. Ultimately, what you’re asked to do is very similar to what you did in the sets of questions 1-8 and 12-20 above. This is repetitious. The idea is that by going through a similar process twice, you will be reinforcing your knowledge. b. The specifications are given in a way slightly different from the previous problem set. This is not critically important. The point is that test questions can be phrased in different ways. You need to have a handle on what is being asked regardless of exactly how it’s asked.

Here is the new class needed for the following questions:

public class NamedPolygon
{
private String name; private double area;

public NamedPolygon(double initarea) { name = “”; area = initarea; }

public void setName(String aname) { name = aname; }

public String getName() { return name; }

public double getArea() { return area; }
}

21. Either show the output of or explain the error in the following fragment of code which makes use of the NamedPolygon class. Give your answer in the space below.

NamedPolygon mypoly1 = new NamedPolygon(12.0);
NamedPolygon mypoly2 = new NamedPolygon(15.0); mypoly1 = mypoly2; mypoly1.setName(“box”); myterminal.println(mypoly2.getName());

Questions 22-25. Write a program that makes use of the NamedPolygon class defined above. The beginning code is provided. Follow the specifications given. You should complete the program, enter it, compile it, debug it, and run it, and hand in a copy of the source code and the test run output.

22. Print a prompt for the user to enter a name and take in a value for myname using myterminal; print a prompt for the user to enter an area and take in a value for myarea using myterminal. 23. Construct mypoly, making sure that the numerical data variable is initialized with the value obtained from the user. 24. Set the name of mypoly to the name given by the user. 25. Using the appropriate method, retrieve the value of area of mypoly, store it back into the variable myarea, and then print this value out.

public class Assignment4PolygonProg
{
public static void main(String[] args) { MyTerminalIO myterminal = new MyTerminalIO(); NamedPolygon mypoly; String myname; double myarea;

Similar Documents

Premium Essay

Unit 4 Assignment 4

...Unit 4 Assignment 4 Non- electronic communication involves the distribution of a message usually in the form of: Reports, Letters, Flow Charts, Invoices and even Verbal Communication amongst employees. This form of communicating is not as popular as it once was, but it provides businesses with other avenues to communicate instead of electronic communication. Furthermore, different types of communication suit contrasting businesses in addition to, the preference of people involved within a business. What Is Non- Electronic Communication? Electronic and Non- Electronic Sources of Business Information Sources of business information can come in a variety of different forms which include: Newspapers, Websites, Books, Posters, Directories, Databases, Government Statistics and so forth. Business information is basically information gathered of relevance to a business and its environment. Businesses use different sources of information as a way of understanding the markets they entering into, their competitors and how the company can grow. Moreover, different sources of business information serve contrasting purposes. Firstly, electronic communication involves the use of technology to distribute a particular message across. Examples of electronic communication include: the use of Mobile Devices, Video conferencing, Twitter, Facebook and other Social Media Websites, as well as, Electronic Mail. This is an effective way of communicating in a business environment as it is cost effective...

Words: 665 - Pages: 3

Premium Essay

Unit 4 Assignment

...Assignment Unit 4 Candace House CJ140 March 26, 2013 Assignment Unit 4 There are two legal terms “search” and “seizure”. The legal term search means to examine another's premises to look for evidence of criminal activity. Under the 4th and 14th Amendments it is unconstitutional for law enforcement officers to conduct a search without a "search warrant" issued by a judge or without facts which give the officer "probable cause" to believe evidence of a specific crime is on the premises if there is not enough time to obtain a search warrant. The legal term seizure means the taking by law enforcement officers of potential evidence in a criminal case. The constitutional limitations on seizure are the same as for search. Thus, evidence seized without a search warrant or without "probable cause" to believe a crime has been committed and without time to get a search warrant, cannot be admitted in court, nor can evidence traced through the illegal seizure. Basically what all this means is that when evidence is being collected in a search and seizure it has to be done by protocol otherwise the criminal may walk free. An element that is needed with both the terms search and seizure is probable cause. Without the probable cause then we cannot legally search a person or their property and take any evidence. Search warrants may also be needed, provided that there is enough time to obtain a search warrant. A third element between the two terms is where there is the ability of doing...

Words: 622 - Pages: 3

Premium Essay

Unit 4 Assignment

...William Clark January 8, 2013 Unit 4 Assignment GB519 Measurement and Decision Making Prof. Stanley Self Special Order Earth Baby Inc. (EBI) recently celebrated its tenth anniversary. The company produces organic baby products for health-conscious parents. These products include food, clothing, and toys. Earth Baby has recently introduced a new line of premium organic baby foods. Extensive research and scientific testing indicate that babies raised on the new line of foods will have substantial health benefits. EBI is able to sell its products at prices higher than competitors’ because of its excellent reputation for superior products. EBI distributes its products through high-end grocery stores, pharmacies, and specialty retail baby stores. Joan Alvarez, the founder and CEO of EBI recently received a proposal from an old business school classmate, Robert Bradley, the vice president of Great Deal Inc (GDI), a large discount retailer. Mr. Bradley proposes a joint venture between his company and EBI, citing the growing demand for organic products and the superior distribution channels of his organization. Under this venture EBI would make some minor modifications to the manufacturing process of some of its best-selling baby foods and the foods would then be packaged and sold by GDI. Under the agreement, EBI would receive $3.10 per jar of baby food and would provide GDI a limited right to advertise the...

Words: 792 - Pages: 4

Premium Essay

Assignment Unit 4

...After researching about energy in Erie, PA, I learned a lot. In this paper I will discuss four different areas. First, we will talk about three forms of energy that are majorly used in the area, where they originate from and whether they are nonrenewable or renewable. Second, we will discuss four renewable energy sources and why they would be good for my area. Next, we will talk about the advantages and disadvantages about the four renewable sources. Last, we will talk about three areas where I can reduce energy in my home. These areas are all very important so let’s get started. First, the three energies that are used the most in Erie are coal, natural gas, and nuclear electric power. Coal, is nonrenewable due to it taking millions of years to create. It is created form peat which is plants and other life forms die and sink to the bottom of swampy areas (energy4me.org pg.1). Natural gas is the next most used, which is made from decaying prehistoric plant and animal remains that is turned into a vapor, which is nonrenewable also (energy4me.org pg. 1). The last item would be nuclear electric power which is the energy in the nucleus or core of an atom, which is nonrenewable (energy4me.org pg. 1). Also energy needs do change throughout the year; this would be mainly due to the weather. My heat is gas, so I use more gas during the winter then in the summer. It changes all the time. Renewable energy sources that could work in my area would be hydro conventional, wind...

Words: 831 - Pages: 4

Premium Essay

Mgm501 Unit 4 Assignment

...Running head: UNIT FOUR ASSIGNMENT 1 UNIT FOUR ASSIGNMENT 5 Unit Four Assignment ? Annotated Bibliography Michelle Kinyungu Kaplan University GM501-01: Management Theories and Practices II Dr. Carrie A. O?Hare February 3, 2016 Unit Four Assignment ? Annotated Bibliography Academic Article/Annotation Format The following peer-reviewed, academic journal article has been secured from the Virtual Library at Kaplan University. The article has been formatted using the APA hanging indent format. The article reference is shown below and in the References. References Zaugg,...

Words: 1062 - Pages: 5

Premium Essay

Unit 4 Assignment 1

...1 Running head: UNIT 4 ASSIGNMENT 1 Fundamentals of Finance BUS 3062 Rodtrice Johnson 3/7/16 Unit 4 Assignment 1 Dennis Hart 1. Q: Proficient-level: "How do Cornett, Adair, and Nofsinger define risk in the M: Finance textbook and how is it measured?" (Cornett, Adair, & Nofsinger, 2016). Distinguished-level: Describe the risk relationship between stocks, bonds, and T-bills, using the standard deviation of returns as the measure of risk. Answer Proficient-level: Risk is defined as the volatility of an asset’s returns over time. Specifically, the standard deviation of returns is used to measure risk. This computation measures the deviation from the average return. The idea is to use standard deviation, a measure of volatility of past returns to proxy for how variable returns are expected to be in the future. Answer Distinguished-level: Stocks and bonds have very different risk-return characteristics. In general, while stocks are more volatile than bonds, over the long run, stocks are expected to yield higher returns than bonds. By varying the mix of stocks and bonds in a portfolio, an investor can achieve her desired level of risk exposure. However, the level of risk in a portfolio depends not only on the risks of individual assets, but also on the movements of the individual assets in the portfolio. 2. Q: Proficient-level: "What is the source of firm-specific risk? What is the source of market risk?" (Cornett, Adair, & Nofsinger, 2016, p...

Words: 1067 - Pages: 5

Premium Essay

IT560 Unit 4 Assignment

...IT560 Unit 4 Assignment Syed M Amin Kaplan University IT560 Unit 4 Assignment In the last report, it was highlighted that an ERP based system can not only facilitate our employees in making better decisions and giving more productivity but an off-the-shelf ERP solution can also lower the overall cost of doing business by eliminating redundant systems and processes. Also, off-the-shelf ERP software is the easiest to implement and carries lower risks associated with it because of feedback from companies that have already used the same software before. Cost and time are key factors during the selection phase of an Enterprise Resource Planning solution. Customization to prewritten ERP packages is expensive, especially when the software needs to be upgraded. The answer to this is the employment of off-the-shelf ERP software. A...

Words: 941 - Pages: 4

Free Essay

Unit 4 Assignment Brief

...Assignment Title | Unit 4: Communication in Business | Assessor | Peter Green | Date Issued | 13th January 2015 | Hand in Date | 20th March 2015 | Duration (approx.) | 11 weeks | Qualification suite covered | Level 3: BTEC Diploma in Business | Units covered | Unit 4 | Learning aims and objectives | The aim of this unit is to inform you that the collection and management of business information, and the successful communication of that information throughout a business, is critical for the future prosperity of the organisation.Learning outcomes:1. Understand different types of business information2. Be able to present business information effectively3. Understand the issues and constraints in relation to the use of business information in organisations4. Know how to communicate business information using appropriate methods | Durations (approx) | 60 hours | BackgroundCase studiesScenario | Proper collection of data creates an environment where informed decisions can be taken for the benefit of the business. In order to manage information effectively, there must be good communication systems within the organisation, and staff must possess good verbal and written skills in order to communicate and share information. Throughout this unit, you will be researching how one organisation obtains and provides information verbally, via written context, and with the use of multi-media.You have been given the choice of the following organisations to research in order...

Words: 1171 - Pages: 5

Premium Essay

Unit 4 Assignment 2

...Unit 4 Assignment 2: Acceptable Use Policy Definition NT2580 The following acceptable use policy has been designed for Richman Investments and grants the right for users to gain access to the network of Richman Investments and also requires the user to follow the terms of use set forth for network access. Policy Guidelines * The use of peer to peer file sharing is strictly prohibited. This includes FTP. * Downloading executable programs or software from any websites, known or unknown, is forbidden. * Users are not allowed to redistribute licensed or copyrighted material without receiving consent from the company. * Introduction of malicious programs into networks or onto systems will not be tolerated. * Attempts to gain access to unauthorized company resources or information from internal or external sources will not be tolerated. * Port scanning and data interception on the network is strictly forbidden. * Authorized users shall not have a denial of service or authentication. * Using programs, scripts, commands, or anything else that could interfere with other network users is prohibited. * Sending junk mail to company recipients is prohibited. * Accessing adult content from company resources is forbidden. * Remote connections from systems failing to meet minimum security requirements will not be allowed. * Social media will not be accessible on company resources. * Internet...

Words: 263 - Pages: 2

Premium Essay

Pt1420 Unit 4 Assignment

...Unit 4 Assignment Short Answers 1. Modules allow the programmer to write an operation once, and then be able to execute it any time needed later in the code. 2. Header – The starting point of the module Body- The list of statements that belong to the module 3. The program returns to the memory address just after from where the module was called, and continues to execute 4. A local variable is a variable that is declared from within the module. Only statements in that module can access it. 5. A local variable’s scope begins at the variable’s declaration and ends at the end of the module in which it is declared. 6. Passing an argument by value is a one-way communication from the main program to the module. Changes to the parameter variable inside the module do not affect the argument in the calling part of the program. Passing an argument by reference is a two-way communication from the main program to the module and it allows modification of the variable in the calling program 7. Global variables make a program difficult to debug because any statement in a program file can change the value of a global variable. If you find that the wrong value is being stored in the global variable, you have to track down every statement that accesses it to determine where the bad value is coming from. 1. Module timesTen (integer originalNumber by value) Set a = originalNumber * 10 Input a Display “The answer is “, a 5. Module getNumber (integer number...

Words: 483 - Pages: 2

Premium Essay

Sc300 Unit 4 Assignment

...Tammy Kelly Kaplan University SC300: Big Ideas in Science: From Methods to Mutation Unit 4 Assignment Professor Joshua Ford May 22, 2012 Unit 4 Assignment: Dangerous and Natural Energy 1) What patterns do you see in the distribution of earthquakes across the continental United States? The west coast of the US consists of the highest levels of risk by a wide margin, particularly in the south-west (on the pacific tectonic plate fault line). Central Eastern regions bear areas of moderate risk. Northern and South/south-easterly regions bear no significant risk. 2) Locate your home on this map and make a note of the relative risk to you by indicating the color where you live. The USGS also reports on earthquakes around the world. Visit this interactive map to find the latest global earthquake data from the past seven days: http://earthquake.usgs.gov/eqcenter/recenteqsww/ Bridgeport Connecticut - very low probability of occurrence here. This region bears no significant risk to such an event over the next 50 years. 3) What patterns do you see in the distribution of earthquakes around the world? The majority of earthquakes occur on the left hand side of the pacific plate (the fault line between the pacific/Eurasian and pacific/Australasian plates) the right hand side of this plate relates to the fault line where the majority of earthquakes in the US occur. The westerly coast of the South America also has an abundance of earthquakes on the right hand side of the Nazca tectonic...

Words: 888 - Pages: 4

Free Essay

Unit 4 Assignment 1

...UNIT 4. Assignment 1. Copper vs Fiber As the name suggests, fibre optic technology uses pulses of light to carry data along strands of glass or plastic. It's the technology of choice for the government's National Broadband Network (NBN), which promises to deliver speeds of at least 100Mbps. When we're talking about 'speed' were actually talking about throughput (or capacity) — the amount of data you can transfer per unit time. And fiber optics can definitely transfer more data at higher throughput over longer distances than copper wire. For example, a local area network using modern copper lines can carry 3000 telephone calls all at once, while a similar system using fiber optics can carry over 31,000. So what gives it the technical edge over copper wires? Traditional copper wires transmit electrical currents, while fiber optic technology sends pulses of light generated by a light emitting diode or laser along optical fibers. In both cases you're detecting changes in energy, and that's how you encode data. With copper wires you're looking at changes in the electromagnetic field, the intensity of that field and perhaps the phase of the wave being sent down a wire. With fiber optics, a transmitter converts electronic information into pulses of light — a pulse equates to a one, while no pulse is zero. When the signal reaches the other end, an optical receiver converts the light signal back into electronic information, the throughput of the data is determined by the frequency range...

Words: 396 - Pages: 2

Premium Essay

It 590 Unit 4 Assignment

...Veronica McNutt IT590 Unit 4 Assignment Professor DePriest September 2, 2014 Unit 4 Assignment Essay Questions Scenario 1: You are working as a designer for a university that offers a program in Computer Science. One of the tracts is computer security. One of your colleagues has recommended adding a course addressing network security. In this course, students learn about the history of networks and study network attacks that have caused significant damage to the network that was the subject of the attack. During the second term of this two semester course, the students are taught how to hack into a system, how to create malware (including Trojan horses, viruses, and worms), and how to perpetrate a DOS attack. Choose one or more of the ethical theories discussed in Chapter 2 and combine that with research to determine whether this course should be taught. Be sure to discuss both sides of the issue before taking a specific side. Would it make a difference if this were a graduate or PhD level course instead of an undergraduate level course? Explain. Disadvantages According to research, there are many concerns for offering hands-on training to students in a computer network class. According to Trabelsi & Ibrahim (2013), UAE conducted a survey of the students who used the skills learned in the hands-on DOS attack class. Eighty five percent of students used the skills learned outside the isolated network university lab. These concerns would be the following: that the...

Words: 1270 - Pages: 6

Premium Essay

Written Assignment Unit 4

...Running Head: WRITTEN ASSIGNMENT Writing Assignment/ Unit#4 Shannon Brown Kaplan University PA 328 Professor Mighdoll April 16, 2013 The United States of America has an extensive history when dealing with the issues of copyright and what regulations or laws should protect the author. America has been deliberating the issue as early as 1787 when James Madison requested that a provision be added to the constitution that would provide protection to literary authors for a determined time (U.S. Copyright Office). Many individuals and organizations have made a mark in the history of copyright laws and regulations but research proves that the Berne Convention is responsible for setting a standard for international copyright laws. The Berne Convention enjoyed much success by signing over a 160 participating member nations. The United States became a member of this international community in 1989 (U.S. Copyright Office). The Berne Convention is an international agreement intended to protect its member’s against copyright infringement and also to allow protections for as long as 70 years after the death of the author, provided the works have been viewed (U.S. Copyright Office). The Berne Convention is a treaty whose members believe that intellectual property is important and should be held to some degree of copyright protection (eBook Chp.16 2012). The Universal Copyright Convention (UCC) was another organization that worked to protect the intellectual...

Words: 483 - Pages: 2

Premium Essay

Nt1310 Unit 4 Assignment

...According to the CT these 5 children are in the lowest ability group working at First and Second level (Education Scotland ) and have many gaps in their mathematical knowledge, thus she felt that they will benefit from extra sessions on math especially multiplication and division which is the focus for this assignment. I have used the SENA assessment to find out the children’s prior...

Words: 2231 - Pages: 9