我已经创建了一个允许从集合中借用CD的java程序,但是我现在需要创建一个find fee ()方法,它对借入1-20次的CD收取10p费用,对借入21-30次的CD收取20p费用,对于借入30次以上的CD收取购买成本的5%,到目前为止我尝试过的代码如下:
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); } } (以上代码是从底线开始的)
我的代码:
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); } }
}任何答案或回复和帮助将非常感谢,因为我真的很困惑和无法弄清楚这一点。
发布于 2013-11-07 09:33:20
以下内容毫无意义:
{ if (timesborrowed >= 1-19) { cost = '+10p'; }
else if (timesborrowed >= 1-29) { cost = '20p'; }
else if (timesborrowed >= 30) { cost = '+ 10.00/5= 2.00'; } 使用:
if(timesborrowed<20) {cost+=0.10;}
else if (timesborrowed <30) {cost +=-.20;}
else {cost +=2;}我猜你说的p指的是便士或便士,也就是面额的1/100,
发布于 2013-11-07 09:32:06
(timesborrowed >= 1-19) This is actually saying if timesborrowed is >= -18
(timesborrowed >= 1-29) This is actually saying if timesborrowed is >= -28改为这样做
if (timesborrowed < 20)
eiseif (timesborrowed < 30)
elsehttps://stackoverflow.com/questions/19826314
复制相似问题