Revel Chapter 10

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

All financial accounts, regardless of their nature, provide a way to deposit and withdraw money. Define an interface named Account that specifies the following methods: A public method named deposit with a parameter of type Cash. The method should return a boolean value. A public method named withdraw with a parameter of type Cash. The method should return a boolean value.

abstract interface Account { abstract boolean deposit(Cash a); abstract boolean withdraw(Cash b); }

Define an interface named GUIComponent that specifies the following methods: A public void method named onClick with a single int parameter A public void method named onCursorFocus with a single int parameter Three overloaded public methods named move, all returning a boolean value: one that has two int parameters the second that has a single parameter of type Position the third that has a single parameter of type Dimension A public method named resize that returns a boolean value and has two int parameters

abstract interface GUIComponent { public abstract void onClick(int a); public abstract void onCursorFocus(int a); public abstract boolean move(int a, int b); public abstract boolean move(Position a); public abstract boolean move(Dimension a); public abstract boolean resize(int a, int b); }

All communication devices, regardless of the type, must have a way to transmit and receive data. Define an interface named CommDevice that specifies the following methods: a public method named transmit that accepts two arguments: a reference to a Destination object, and a String (in that order). The method should return a boolean value. a public method named receive that accepts an argument of type Duration, and returns a String.

interface CommDevice { boolean transmit(Destination dest, String text); String receive(Duration timeout); }

Write a constructor for SavingsAccount that accepts three arguments, in the following order: a String, for the account holder's name an int, for the account number a double, for the interest rate The String and the int should be passed to the BankAccount constructor, and the double should be assigned to the interestRate field.

public SavingsAccount(String name, int socSecNum, double interestRate) { super(name, socSecNum); this.interestRate = interestRate; }

Write an abstract class named Phone that contains the following members: a private String field named phoneNumber a constructor that accepts a String argument that is assigned to the phoneNumber field a public method named getPhoneNumber that returns the value of the phoneNumber field a public toString method that returns the phoneNumber in the form "#(phoneNumber)" where phoneNumber is the value of the phoneNumber field a public abstract method named createConnection that accepts a reference to a Network object as its argument. The method should return a boolean value. a public abstract method named closeConnection that accepts no arguments and returns no value.

public abstract class Phone { private String phoneNumber; public Phone(String a) { phoneNumber=a; } public String getPhoneNumber() { return phoneNumber; } public String toString() { return "#(" + phoneNumber + ")"; } public abstract boolean createConnection(Network a); public abstract void closeConnection(); }

Write a class definition for an abstract class named Vehicle that contains the following members: a private double field named maxSpeed a protected double field named currentSpeed a constructor accepting a double argument that is used to initialize the maxSpeed field a public abstract method named accelerate that accepts no parameters and returns nothing. a method, getCurrentSpeed, that returns the value of currentSpeed a public method named getMaxSpeed that returns the value of the maxSpeed field a public method named pedalToTheMetal that accepts no arguments, and repeatedly calls the accelerate method until the speed of the vehicle is equal to maxSpeed. The pedalToTheMetal method returns nothing.

public abstract class Vehicle { public Vehicle(double maxSpeed) {this.maxSpeed = maxSpeed;} public abstract void accelerate(); public double getCurrentSpeed() {return currentSpeed;} public double getMaxSpeed() {return maxSpeed;} public void pedalToTheMetal() { while (currentSpeed < maxSpeed) accelerate(); } protected double currentSpeed; private double maxSpeed; }

Define a class named BankAccount that implements the Account interface described above, and has the following members: a private int field named balance a constructor that accepts an int that is used to initialize the balance field an implementation of the deposit method that adds its parameter to the balance field. The method should return the new balance. an implementation of the withdraw method that determines whether its argument is less than or equal to the balance field, and if so, decreases the balance field by the value of the argument and returns true. Otherwise, it leaves the balance unchanged and returns false.

public class BankAccount implements Account{ private int balance; public BankAccount(int initialBalance) { this.balance = initialBalance; } @Override public int deposit(int depostCash) { balance = balance + depostCash; return balance; } @Override public boolean withdraw(int withdrawCash) { if(balance>=withdrawCash){ balance = balance - withdrawCash; return true; } return false; } }

Write the definition of a class named CheckingAccount, that is a subclass of BankAccount. The CheckingAccount class should contain: a boolean field named overdraft. (If overdraft is true, checks that are larger than the current account balance can be written.) a constructor that accepts a String and a boolean. The String parameter contains the account holder's name and should be passed to the superclass (BankAccount) constructor. The boolean parameter should be used to initialize the overdraft field. a public method named hasOverdraft, that returns a boolean. The method should return the value of the overdraft field. a public method named clearCheck that accepts a double argument and returns a boolean. The argument is the amount of a check. The method should determine whether the amount of the check can be cashed—this will be the case if the amount is less than the balance in the account, or if the account allows overdraft. If the check can be cashed, the clearCheck method returns true, and also calls the withdraw method to update the account balance; otherwise, the clearCheck method returns false.

public class CheckingAccount extends BankAccount{ private boolean overdraft; public CheckingAccount(String s, boolean b){ super(s); overdraft = b; } public boolean hasOverdraft(){ return overdraft; } public boolean clearCheck(double d){ if(d < getBalance() || overdraft) { withdraw(d); return true; } else return false; } }

Write a public class named Customer, which is a subclass of the Person class. The Customer class should have the following fields: customerNumber, a String to hold a customer number receiveMail, a boolean to indicate whether the customer wishes to be on a mailing list The Customer class should also have a constructor that accepts five arguments, in the following order: A String for the customer's name A String for the customer's address A String for the customer's telephone number A String for the customer's customer number A boolean to indicate whether the customer wishes to be on a mailing list The constructor should pass the first three arguments to the superclass constructor and use the last two arguments to initialize the customerNumber and receiveMail fields. In addition, the Customer class should have public accessor methods and public mutator methods for each of the class's fields.

public class Customer extends Person{ private String customerNumber; private boolean receiveMail; public Customer(String n, String a, String num, String cusNum, boolean mail) { super(n, a, num); customerNumber = cusNum; receiveMail= mail; } public String getCustomerNumber() { return customerNumber; } public boolean getReceiveMail() { return receiveMail; } public void setCustomerNumber(String cusNum) { customerNumber = cusNum; } public void setReceiveMail(boolean mail) { receiveMail = mail; } }

Write a public class named HighSchoolStudent that is a subclass of the Student class. The HighSchoolStudent class should contain: a constructor that accepts a String which is passed as an argument to the superclass constructor a toString method that returns "high school student at X" where X is the name of the school the student attends. This method must use the toString method of its superclass.

public class HighSchoolStudent extends Student { public HighSchoolStudent(String school) { super(school); } public String toString() { return "high school " + super.toString(); } }

Write a public class named Point3D that is a subclass of the Point class. The Point3D class should have the following members: a private int field named z a constructor that assigns 0 to the z field a public void method named setZ that accepts an int argument. The argument's value should be assigned to the z field a public method named getZ that returns the value of the z field

public class Point3D extends Point { private int z; Point3D() { z = 0; } public void setZ(int zpoint) { z = zpoint; } public int getZ() { return z; } }

Assume a class named BankAccount already exists. Write a public class named SavingsAccount that is a subclass of the BankAccount class. The SavingsAccount class should contain the following members: a private field named interestRate, of type double a constructor that accepts an argument of type double. The argument's value should be assigned to the interestRate field

public class SavingsAccount extends BankAccount { private double interestRate; public SavingsAccount(double interestRate) { this.interestRate = interestRate; } }

Write a public class named Triangle that is a subclass of the Polygon class. The Triangle class should have the following members: a private int field named base a private int field named height a constructor that assigns 3 to the numSides field and assigns 0 to the base and height fields a public void method named setBase that accepts an int argument. The argument's value should be assigned to the base field a public void method named setHeight that accepts an int argument. The argument's value should be assigned to the height field a public method named getBase that returns the value of the base field a public method named getHeight that returns the value of the height field a public method named getArea that returns the area of the triangle as a double. Use the following formula to calculate the area: Area = (height * base) / 2.0

public class Triangle extends Polygon { private int base; private int height; public Triangle() { setNumSides(3); base=0; height=0; } public void setBase(int b) { base=b; } public void setHeight(int h) { height=h; } public int getBase(){ return base; } public int getHeight(){ return height; } public double getArea(){ return 0.5*base*height; } }

In this exercise, you are to write a clear method that can be a member of the CameraPhone class, to override the clear method in the Phone class. The method should call the superclass's clear method, and then call the album object's clear method. The method should be public, it should accept no arguments, and it should return no value.

public void clear() { super.clear(); album.clear(); }


संबंधित स्टडी सेट्स

Product Costs Versus Period Costs (Chapter 12: Manufacturing Cost Accounting) 854-868

View Set

Theodore Roosevelt: The Beginnings of Progressive Presidencies

View Set

HESI Practice Questions - Foundations

View Set

Milady's chapter 19 wigs and hair additions

View Set

CHAPTER 60: ASSESSMENT OF NEUROLOGIC FUNCTION

View Set