ARRRG HELP! IM STUCK
807606May 17 2007 — edited May 17 2007Hello there im at portsmouth uni and its my first time studying blue j and java. Now i have created two programs which im in desperate need of help and guidance because i cant get them to work here is a description of what i have to do for them and my code:
/**
* A class that maintains information on a book.
* This might form part of a larger application such
* as a library system, for instance.
ok and heres what the coursework asked me to do:
a) Add two accessor methods to the class. Call them getAuthor and getTitle. Their purpose is to return the author and title fields as their respective results. Test your class by creating some instances and calling the methods.
b) Add two methods printAuthor and printTitle to the outline Book class. These should print the author and title fields in the terminal window.
c) Add a further attribute, pages, to the Book class to store the number of pages. Include an appropriate getPages accessor method for this field.
d) Add a method, printDetails, to the Book class. This should print details of the author, title and pages to the terminal window. It is your choice how the details are formatted.
e) Add a further field, refNumber, to the Book class. This field can store a reference number for a library, for example. It should be of type String and initialised to a zero length String in the constructor as its initial value is not passed in a parameter to the constructor. Instead define a mutator with the following signature:
public void setRefNumber(String ref).
Add a corresponding getRefNumber accessor to help you check that the mutator works correctly.
f) Modify your printDetails method to include printing the reference number but only if it has been set. If it has not been set print �ZZZ� instead.
g) Modify your setRefNumber mutator so that it sets the refNumber field only if the parameter is a string of at least three characters. If it is less than three, then print an error message and leave the field unchanged.
h) Add a further integer field, borrowed, to the Book class. This keeps a count of the number of times a book has been borrowed. Add a mutator, borrow, to the class. This should update the field by 1 each time it is called. Include an accessor, getBorrowed, that returns the value of this field as a result. Modify printDetails so that it includes the value of this field with an explanatory piece of text.
and heres the code:
/**
* A class that maintains information on a book.
* This might form part of a larger application such
* as a library system, for instance.
*
* @author (Insert your name here.)
* @version (Insert today's date here.)
*/
public class Book
{
// The fields.
private String Author;
private String title;
private String Pages;
private String RefNumber;
private int limit;
private int Borrowed;
}
/**
* Set the author and title fields when this object
* is constructed.
*/
{
public class Book(String bookAuthor, String bookTitle, String bookPage, String bookRefNumber)
{
Author = bookAuthor;
title = bookTitle;
page = bookPage;
RefNumber = bookRefNumber;
}
/**
* Accesor method to request borrow
*/
public int getBorrow()
{
return Borrow;
}
/**
*Count the times borrowed
*/
public void borrow(int)
{
borrow = + 1
}
/**
* @Return The Author Title.
*/
public String getAuthor()
{
return Author;
}
/**
* Return The title
* for the book.
*/
public String getTitle()
{
return title;
}
/**
* Return The page numbers
* for the book.
*/
public String getPage()
{
return Page;
}
/**
* Constructor for reference numbers limit
*/
public void setRefNumber(String ref)
{
limit = ref;
value = 0;
}
/**
* Perform a test on the parameters Return refnumber only if it has been set constructor
*/
public String length()
{
if((limit = 3)
value = setRefNumber &&
}
*//
*Print if the limit is less than 3
{
if(RefNumber <= 3))&&
System.out.println("THERE HAS BEEN AN ERROR!");
}
/**
* Return reference numbers
*/
public String getValue()
{
return value;
}
/**
* Print the reference number field but only if it has
* been set and also the author, title, and pages fields and borrow.
*/
public void print()
{
System.out.println(Author + " (" + Title + Author + Page RefNumber + Borrow ")");
}
now i just need to know was i supposed to put some stuff in the other classed not just the book one im just really kinda like f***d off with java atm i like using other l anguages like basic, c and python i find them alot better.
the other program is abit smaller heres what it is supposed to do:
a) Create a new project, jet_exercise, within BlueJ. Edit the details in the project description � the text note you see in the diagram. Create a class, Engine, which contains a single integer field, thrust. Define a constructor that takes no parameters. The thrust field should be set to the value 5 in the constructor. Define the mutators moreThrust and lessThrust, whose effect is to increase and decrease the value of thrust by 5 units respectively. Define an accessor method to return the value of thrust.
b) Modify the Engine class to include three new integer fields: min, max and increment. The values of min and max should be set by parameters passed to the constructor. The value of increment should be set to 5 in the constructor. Modify the definitions of moreThrust and lessThrust so that they use the value of increment rather than an explicit value of 5. Check that everything works as before. Now modify the moreThrust method so it will not allow the value of thrust to be set to a value greater than max. Similarly modify lessThrust. Now add a method called setIncrement that takes a single integer parameter and uses it to set the value of increment. Add a check in the method such that the value of setIncrement cannot exceed 10% of the value in max.
and heres my code:
/**
* Write a description of class Engine here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Engine
{
private int value;
/**
* Constructor for objects of class Engine
*/
public Engine(int thrust)
{
value = thrust;
value = 1;
thrustmin = lessthrust;
thrustmax = morethrust;
increment = setincrement;
}
}
/**
* Set max thrust
*/
public void moreThrust(int maxthrust)
{
moreThrust = maxthrust;
value = maxthrust.increment;
}
}
}
/**
* Set min thrust
*/
public void lessThrust(int minthrust)
{
lessThrust = minthrust;
value = minthrust.increment;
}
/**
* return the value of thurst
*
*/
public int getThrust()
{
return thrust();
}
/**
* Set the increment
*/
public void setIncrement()
{
value.increment();
}
if(thrust.getThrust() == > int/100*10)
maxthrust.increment = ((null);
}
sorry this is all abit much but if someone can give me solutions to what goes where in classes and whats wrong then i will be forever in your debt
thankyou adam kenyon