What attributes would your class have

Assignment Help JAVA Programming
Reference no: EM131134334

Question 1: Written

Write your solutions to both questions (A and B) in a plain text file called Problem1.txt or PDF file called Problem1.pdf. Do NOT submit a .doc, .docx, .rtf or any other kind of file.

A) You are asked to design a Student class that models students at Carleton University.

What attributes would your class have? What methods would your class have?

B) Write a good multiple choice question based on what we have learned so far in the course. The question should have three answers: one best answer and two that are feasible but not the best (or possibly incorrect). Be sure to say which answer is the correct (best) answer for the question and why.

Here is an example (do not submit this as your question).

In the HelloWorld program, what is "public" that appears on the line that defines the main method?

a) An access modifier
b) A member level access modifier
c) A non-access modifier

The best answer is b).
a) is also correct, but b) is better as it is more specific
c) is incorrect.

Question 2: People

The Person class models a person. Each person will have a name (consisting of a first name, middle name, and a surname), an age and a height.

Complete the Person class provided. Your class must have the following methods and constructors: (specifications are given in the skeleton code provided)

public Person(String, String, String, int, int); public Person(String, String, int, int);
public Person();

public String getName(); public int getHeight();
public int[] getHeightFeetAndInches(); public int getAge();

public void setFirstName(String); public void setMiddleName(String); public void setLastName(String); public void setHeight(int);
public void setAge(int);

public String toString();

public static void main(String[]);
There should be no other public attributes or methods in your class. You may add any private attributes or methods that you see fit. Be sure to follow the specifications for each method (and constructor) as given in the skeleton code provided.

The conversion from cm to feet and inches is not exact. It should be the best conversion possible though. If your conversion of h cm is f feet and i inches, where 0 ≤ f and 0 ≤ i < 12, then f and i when converted back to cm is the closest to h for any values of feet (≥ 0) and inches (between 0 and 11). In particular, converting f feet and i ± 1 inches will give a cm value further away from the original h than converting f feet and i inches will.

Note: Pay special attention to the specification of the output of all methods. In particular, the output of the toString and getName methods must follow the specifications exactly. A misplaced comma or missing/extra space, for example, will result in significant marks lost.

Question 3: Fish

In the problem you will implement a Fish class that will represent fish in a video game.

A skeleton (partial version) of the class is given below. You will need to implement all non-getter methods and constructors. Full descriptions are given in the provided Fish.java file. You may add any private attributes or methods you see fit.
public class Fish{

/* constants for fish bowl and fish parameters (DO NO CHANGE THESE) */ public static final int WIDTH = 600;
public static final int HEIGHT = 400; public static final int MAX_SPEED = 5; public static final int MAX_SIZE = 30;

/* fish attributes */
private int id; // unique id for each fish private int size; // 1 <= size <= MAX_SIZE private int health;

private double x, y; // x,y coordinates of the fish private double dx, dy; // x,y speed values for the fish

/*constructors (you implement these)*/ public Fish(int size, int health)
public Fish(int size, int health, double x, double y)
public Fish(int size, int health, double x, double y, double dx, double dy)

/* provided getters */ public int getID() public int getSize() public int getHealth() public double getX() public double getY() public double getDX() public double getDY()

/*methods (you implement these)*/ public boolean eat(Fish other) public Fish mate(Fish other) public void swim()
public boolean closeEnough(Fish other)

/* provided helper methods */ public boolean hasMated(Fish mater)
public boolean beenEaten(Fish eater) public String toString()
}

In the closeEnough method, you will need to determine if two fish are close enough to each other. Two fish will be close enough if the distance between them (based on their x and y coordinates) is less than or equal the sum of their sizes. Recall that the distance d

between point (x1, y1) and point (x2, y2) is given by

       ________________

d =  (x1 - x2)2 + (y1 - y2)2

For random values, use the Math.random. It generates a random number in the range [0.0, 1.0). If you want a random value between 0 and 35, you can use Math.random()*35. Alternatively, you can use the Random class.

For this problem, you do not have to consider the size of the fish when hitting a wall.

Just use the x, y coordinates (which we assume is the centre of the fish).

Question 4: Cash Register

In this problem you will complete the provided CashRegister class. This class models a simplified cash register. Our cash register will only hold loonies, five dollar bills, ten dollar bills, twenty dollar bills, and fifty dollar bills. The functionality (behaviour) of our cash register is that it processes transactions (purchasing and returning items) and tries to ensure it has adequate money in it.

An Item class is provided for this problem. An item is something that is bought (and possibly returned). It has a name and a price. All prices are in dollars. An item object is immutable so once it is created it cannot be changed.

A Money class is provided for this problem. This is one way in which money is represented in this problem. Money objects are also immutable. Once a money object is created there is no way to change its state (you need to create a new object if you want to change it). Another way money can be represented in this problem is to use an array of integers. The array will have five (5) elements and correspond to the number of loonies, five dollar bills, ten dollar bills, twenty dollar bill and fifty dollar bills, in that order. So, [3, 1, 0, 2, 0] would represent $48.

Complete the following constructors and methods in the CashRegister class. Full descrip- tions are given in the comments in the provided CashRegister.java file. You are free to add any private attributes and helper methods as you see fit.

/* constructors */ public CashRegister()
public CashRegister(Money money) public CashRegister(int[] money)
public CashRegister(int n1, int n5, int n10, int n20, int n50)

/* getters */ public int get1() public int get5()
public int get10() public int get20() public int get50()
public int getTotalValue() public int[] getAll()
public Money getMoney()

/* methods */
public Money purchaseItem(Item item, Money payment) public Money returnItem(Item item)
public CashRegister updateMoney() public CashRegister allLoonies()

When a purchase is being processed, you first add the payment to the register's total money and make change based on this combined amount of money. If you are unable to give exact change for the purchase, you will call the updateMoney method. The updateMoney method allows you exchange all the current money in the register with an equivalent amount (but different combination of loonies and bills). You decide how updateMoney works. If the register is still unable to make exact change after calling updateMoney, then allLoonies is called which exchanges all money in the register for loonies. For example, if money in the register is currently [2, 3, 5, 1, 1], then after calling allLoonies, the money is [137, 0, 0, 0, 0].

Attachment:- Java.rar

Reference no: EM131134334

Questions Cloud

What is the probability of eating potato salad : Are these events mutually exclusive? Why or why not? What is the probability of eating potato salad given that a person was a case? Show your work
How conflict management relates to effectiveness as leader : Think about who was involved, how it was resolved (if it was), and how it might have been handled more effectively. Identify the conflict management style(s) employed by various individuals, including ineffective responses or no response to the sit..
Application the efficient market hypothesis : Suppose that a share of Microsoft had a closing price yesterday of $90, but new information was announced after the market closed that caused a revision in the forecast of the price next year to go to $120.
What makes this an endogenous growth model : Interpret a . What are we really saying when we assume that the labor-augmenting technology, A , is proportional to the level of capital per worker?
What attributes would your class have : What attributes would your class have? What methods would your class have - In the HelloWorld program, what is "public" that appears on the line that defines the main method?
Why populations react biologically to a social condition : Ecosocial theory provides health professionals with an opportunity to understand why populations react biologically to a social condition. It is these interactions between biology and social conditions that can contribute to an inequitable distrib..
Calculating the amount of disability benefits : 1. Calculating the Amount of Disability Benefits. Georgia Braxton, a widow, has take-home pay of $600 a week. Her disability insurance coverage replaces 70 percent of her earnings after a four-week waiting period. What amount would she receive in ..
Characterize the set of equilibria for this model : Does the addition of the variable rate of population growth to this model help you explain anything that a simpler two-sector model with a fixed rate of growth, or a one-sector model with variable population growth, cannot?
The digital electronic quotation system : The digital electronic quotation system (deqs) corporation pays no cash dividends currently and is not expected to for the next 5 years. its latest EPS was $10, all of which was reinvested in the company.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create three new threads

Write a program (in C, or Java, or C++, or C#) that creates three new threads (besides the already existing main thread) and synchronizes them in such a way that each thread displays it's thread id in turn for 5 iterations

  T an array using insertion sort and track the number of swap

How to sort an array using insertion sort and track teh number of swaps during the sorting

  Write an application in which the user can enter a date

Write an application in which the user can enter a date using digits and slashes (for example, " 6/24/2012 " ), and receive output that displays the date with the month shown as a word

  Write a program that prompts the user to enter a point

Write a program that prompts the user to enter a point (x,y) and checks whether the point is within the rectangle centered at (0,0) with width 10 and height 5

  Calculate payback period and net present value

Calculate payback period (PBP), net present value (NPV), and internal rate of return (IRR). Which project do you recommend for development? Support your recommendation.

  Program implements the functionality of a deck of cards

Write a complete program using "ECLIPS" that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two..

  Method that accepts a string object

Word Counter Write a method that accepts a String object as an argument and returns the number of words it contains. For instance, if the argument is "Four score and seven years ago" the method should return the number

  Implement the client and server components

The basic requirements of this assignment are to implement the client and server components as discussed above. The basic protocol of the system is described below: The operations of the client are: SEND_SERVER_MESG: send a basic text message to th..

  Write a number guessing game in java

ou have to write a number guessing game in Java. The program should have three difficulty levels, each one having a different maximum number. After the user selects a difficulty,

  Write a method reversefirstk

Write a method reverseFirstK that accepts an integer k and a queue of integers as parameters and reverses the order of the first k elements of the queue, leaving the other elements in the same relative order.

  Write down the business needs for a computer program and

write the business requirements for a computer program and identify which entities are to be modeled using object

  Create a book class which stores the information

You run a small library. Ask the user to provide information for several books. The information must include the author, title and publisher of each book.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd