Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M91890853
  • Price:- $75

Priced at Now at $75, Verified Solution

Have any Question?


Related Questions in Java

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As