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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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