I have created a java program that allows CD to be borrowed from a collection, however i now need to create a method find fee (), which applies 10p charge for cds borrowed 1-20 times, 20p charge for cds borrowed 21-30 times, 5% of purchase cost charged for cds borrowed more than 30 times, my attempted code so far :
public void borrow(String personBorrowed)
{
person = personBorrowed;
inStock = false;
timesBorrowed = timesBorrowed + 1;
}
public void main(String[] args)
{ if (timesborrowed >= 1-19) { cost = '+10p'; }
else if (timesborrowed >= 1-29) { cost = '20p'; }
else if (timesborrowed >= 30) { cost = '+ 10.00/5= 2.00'; }
System.out.println("Cost = " + cost); } }
(above code is from the bottom line)
my code:
public class CD
{
// instance variables - replace the example below with your own
private String title;
private String artist;
private int noOfTracks;
private double cost;
private boolean inStock;
private String person;
private int timesBorrowed;
private boolean returnCD;
/**
* Constructor for objects of class CD
*/
public CD(String newTitle, String newArtist,int newNoOfTracks,double newCost)
{
// initialise instance variables
title = newTitle;
artist = newArtist;
noOfTracks = newNoOfTracks;
cost = newCost;
inStock = true;
person = null;
timesBorrowed = 0;
}
/**
* Default Constructor for Testing
*/
public CD()
{
// initialise instance variables
title = "Blue Print";
artist = "Jay Z";
noOfTracks = 15;
cost = 10.00;
inStock = true;
person = null;
timesBorrowed = 0;
}
/**
* An example of a method - replace this comment with your own
*/
public String getTitle()
{
return title;
}
/**
* An example of a method - replace this comment with your own
*/
public String getArtist()
{
return artist;
}
/**
* An example of a method - replace this comment with your own
*/
public int getNoOfTracks()
{
return noOfTracks;
}
/**
* An example of a method - replace this comment with your own
*/
public double getCost()
{
return cost;
}
/**
* An example of a method - replace this comment with your own
*/
public void printDetails()
{
System.out.println("Title: " + title);
System.out.println(" ");
System.out.println("Artist: " + artist);
System.out.println(" ");
System.out.println("Number of Tracks: " + noOfTracks);
System.out.println(" ");
System.out.println("Cost: " + cost);
}
/**
* An example of a method - replace this comment with your own
*/
public void borrow(String personBorrowed)
{
person = personBorrowed;
inStock = false;
timesBorrowed = timesBorrowed + 1;
}
public void main(String[] args)
{ if (timesborrowed >= 1-19) { cost = '+10p'; }
else if (timesborrowed >= 1-29) { cost = '20p'; }
else if (timesborrowed >= 30) { cost = '+ 10.00/5= 2.00'; }
System.out.println("Cost = " + cost); } }
}
any answers or replies and help would be greatly appreciated as I really confused and cant figure this out.