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

  Build impressive piece of software to explore data sets

Assemble the GUI interactors and implement the NameSurferEntry class - build an impressive piece of software to explore interesting data

  How are the packaged files viewed

How are several Java files packaged, Why is there a need for packaging java files and How are the packaged files viewed?

  Java code that needs to be coded-complex number class

Just a Java Code that needs to be coded. Your given the design, just needs the methods and such to be fixed. This is for a Complex Number class.

  Web application that allows user to specify six lottery nums

Write a web application that allows a user to specify six lottery numbers. Generate your own combination on the server, and then print out both combinations together with a count of matches.

  Subtyping and exceptions

In Java, a method that can throw an exception (other than from a subclass of Error or RuntimeException) must either catch the exception or specify the types of possible exceptions with a throws clause in the method declaration. For example, a meth..

  Nearest tenth of a percent

What interest rate is required to the nearest tenth of a percent, for an investment to triple in 20 years if the interest is compounded continuously?

  You are a mighty warrior and armed with your trusty bow and

you are a mighty warrior and armed with your trusty bow and 3 arrows you enter the caves in search of the mighty

  Discuss: inheritance loops and conditional statements

"The process of identifying the classes or functions for replacement" - I you can also define things that are used in the program. ie, define and discuss: inheritance, loops, conditional statements, variables, methods, objects, IDEs, and so on.

  Explain java-oriented microprocessors presented by sun

Research the latest Java-oriented microprocessors presented by Sun. In what ways are they optimized to implement Java programs?

  Expain what is runtime polymorphism

Expain What is runtime polymorphism in java programming?

  Development of database systems

Prior to the development of database systems, file I/O was how information was stored and retrieved. Give your opinion on what you believe we have gained by using databases. Explain whether or not you believe files had any advantages.

  Display the value stored at the index

Display the value stored at the index. Take a screenshot to verify that the words in your Array or ArrayList are displayed successfully.

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