import java.util.*;public class proj1 { public static void main(String[] args) { // TODO Auto-generated method stub //System.out.println("aaaaa"); Hashtable quality = new Hashtable(); // create a new hash table Float price1 = new Float(3.00F); // if it is mint, then the price will be 3 time that of the base price quality.put("mint", price1); // the first element is added in the hashtable Float price2 = new Float(2.00F); // if it is near mint, the price will be twice that of the base price quality.put("near mint", price2); // the second element is added Float price3 = new Float(1.50F); // if the book is very fine, the price is 1.5 times of the base price quality.put("very fine", price3); // 3rd element is added Float price4 = new Float(1.00F); // if the book is fine, the price is the same as the base price quality.put("fine", price4); // the 4th element is added Float price5 = new Float(0.50F); // if the book is good, the price will be half of the base price quality.put("good", price5); // the 5th element is added Float price6 = new Float(0.25F); // if the book is poor, the price is quarter of the base price quality.put("poor", price6); // the 6th element is added
Comic[] comics = new Comic[3]; // create a new array with three comics in it comics[0] = new Comic("Amazing Spider-Man", "1A", "very fine", 5400.00F); // the first element of the comic array is added comics[0].setPrice((float)quality.get(comics[0].condition)); // set the final price of the first book comics[1] = new Comic("Incredible Hult", "181", "near mint", 770.00F); // the first element of the comic array is added comics[1].setPrice((float)quality.get(comics[1].condition)); // set the final price of the first book comics[2] = new Comic("Cerebus", "1A", "good", 260.00F); // the first element of the comic array is added comics[2].setPrice((float)quality.get(comics[2].condition)); // set the final price of the first book
for (int i = 0; i < comics.length; i++) { System.out.println("Title: " + comics[i].title + ";"); // to print the title of the book System.out.println("Issue number: " + comics[i].issueNumber + ";"); // to print the issue number of the book System.out.println("Condition: " + comics[i].condition + ";"); // to print the condition of the book System.out.println("Price: $" + comics[i].price + "; \n"); // to print the final price of the book } } public class Comic {
String title; // the title of the book String issueNumber; // the issue number of the book String condition; // the condition of the book float basePrice; // the base price of the book float price; // the actual price of the book
Comic(String inTitle, String inIssueNumber, String inCondition, Float inBasePrice) { // the constructor for the 'Comic' title = inTitle; // set the book's title as the input title issueNumber = inIssueNumber; // set the book's issue number as the input one condition = inCondition; // set the book's condition as the input one basePrice = inBasePrice; // set the book's base price as the input one }
void setPrice(Float factor) { // a function to set the final price of the book float multiplier = factor.floatValue(); // transfer 'factor' to another float number price = basePrice * multiplier; // set the final price for the book } }}
import java.util.*;public class proj1 { public static void main(String[] args) { // TODO Auto-generated method stub //System.out.println("aaaaa"); Hashtable quality = new Hashtable(); // create a new hash table Float price1 = new Float(3.00F); // if it is mint, then the price will be 3 time that of the base price quality.put("mint", price1); // the first element is added in the hashtable Float price2 = new Float(2.00F); // if it is near mint, the price will be twice that of the base price quality.put("near mint", price2); // the second element is added Float price3 = new Float(1.50F); // if the book is very fine, the price is 1.5 times of the base price quality.put("very fine", price3); // 3rd element is added Float price4 = new Float(1.00F); // if the book is fine, the price is the same as the base price quality.put("fine", price4); // the 4th element is added Float price5 = new Float(0.50F); // if the book is good, the price will be half of the base price quality.put("good", price5); // the 5th element is added Float price6 = new Float(0.25F); // if the book is poor, the price is quarter of the base price quality.put("poor", price6); // the 6th element is added
Comic[] comics = new Comic[3]; // create a new array with three comics in it comics[0] = new Comic("Amazing Spider-Man", "1A", "very fine", 5400.00F); // the first element of the comic array is added comics[0].setPrice((float)quality.get(comics[0].condition)); // set the final price of the first book comics[1] = new Comic("Incredible Hult", "181", "near mint", 770.00F); // the first element of the comic array is added comics[1].setPrice((float)quality.get(comics[1].condition)); // set the final price of the first book comics[2] = new Comic("Cerebus", "1A", "good", 260.00F); // the first element of the comic array is added comics[2].setPrice((float)quality.get(comics[2].condition)); // set the final price of the first book
for (int i = 0; i < comics.length; i++) { System.out.println("Title: " + comics[i].title + ";"); // to print the title of the book System.out.println("Issue number: " + comics[i].issueNumber + ";"); // to print the issue number of the book System.out.println("Condition: " + comics[i].condition + ";"); // to print the condition of the book //System.out.println("Price: $" + comics[i].price + "; \n");//比较下,就是这块空格的问题,可能是中文下的空格 System.out.println("Price:$"+comics[i].price + "; \n"); // to print the final price of the book } } public class Comic {
String title; // the title of the book String issueNumber; // the issue number of the book String condition; // the condition of the book float basePrice; // the base price of the book float price; // the actual price of the book
Comic(String inTitle, String inIssueNumber, String inCondition, Float inBasePrice) { // the constructor for the 'Comic' title = inTitle; // set the book's title as the input title issueNumber = inIssueNumber; // set the book's issue number as the input one condition = inCondition; // set the book's condition as the input one basePrice = inBasePrice; // set the book's base price as the input one }
void setPrice(Float factor) { // a function to set the final price of the book float multiplier = factor.floatValue(); // transfer 'factor' to another float number price = basePrice * multiplier; // set the final price for the book } }}
// TODO Auto-generated method stub
//System.out.println("aaaaa");
Hashtable quality = new Hashtable(); // create a new hash table
Float price1 = new Float(3.00F); // if it is mint, then the price will be 3 time that of the base price
quality.put("mint", price1); // the first element is added in the hashtable
Float price2 = new Float(2.00F); // if it is near mint, the price will be twice that of the base price
quality.put("near mint", price2); // the second element is added
Float price3 = new Float(1.50F); // if the book is very fine, the price is 1.5 times of the base price
quality.put("very fine", price3); // 3rd element is added
Float price4 = new Float(1.00F); // if the book is fine, the price is the same as the base price
quality.put("fine", price4); // the 4th element is added
Float price5 = new Float(0.50F); // if the book is good, the price will be half of the base price
quality.put("good", price5); // the 5th element is added
Float price6 = new Float(0.25F); // if the book is poor, the price is quarter of the base price
quality.put("poor", price6); // the 6th element is added
Comic[] comics = new Comic[3]; // create a new array with three comics in it
comics[0] = new Comic("Amazing Spider-Man", "1A", "very fine", 5400.00F);
// the first element of the comic array is added
comics[0].setPrice((float)quality.get(comics[0].condition));
// set the final price of the first book
comics[1] = new Comic("Incredible Hult", "181", "near mint", 770.00F);
// the first element of the comic array is added
comics[1].setPrice((float)quality.get(comics[1].condition));
// set the final price of the first book
comics[2] = new Comic("Cerebus", "1A", "good", 260.00F);
// the first element of the comic array is added
comics[2].setPrice((float)quality.get(comics[2].condition));
// set the final price of the first book
for (int i = 0; i < comics.length; i++) {
System.out.println("Title: " + comics[i].title + ";");
// to print the title of the book
System.out.println("Issue number: " + comics[i].issueNumber + ";");
// to print the issue number of the book
System.out.println("Condition: " + comics[i].condition + ";");
// to print the condition of the book
System.out.println("Price: $" + comics[i].price + "; \n");
// to print the final price of the book
}
}
public class Comic {
String title; // the title of the book
String issueNumber; // the issue number of the book
String condition; // the condition of the book
float basePrice; // the base price of the book
float price; // the actual price of the book
Comic(String inTitle, String inIssueNumber, String inCondition, Float inBasePrice) {
// the constructor for the 'Comic'
title = inTitle; // set the book's title as the input title
issueNumber = inIssueNumber; // set the book's issue number as the input one
condition = inCondition; // set the book's condition as the input one
basePrice = inBasePrice; // set the book's base price as the input one
}
void setPrice(Float factor) { // a function to set the final price of the book
float multiplier = factor.floatValue(); // transfer 'factor' to another float number
price = basePrice * multiplier; // set the final price for the book
}
}}
代码你从其他地方复制的?? 有奇怪的字符, 你把加号前后的空白都删掉试试...
import java.util.*;public class proj1 { public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println("aaaaa");
Hashtable quality = new Hashtable(); // create a new hash table
Float price1 = new Float(3.00F); // if it is mint, then the price will be 3 time that of the base price
quality.put("mint", price1); // the first element is added in the hashtable
Float price2 = new Float(2.00F); // if it is near mint, the price will be twice that of the base price
quality.put("near mint", price2); // the second element is added
Float price3 = new Float(1.50F); // if the book is very fine, the price is 1.5 times of the base price
quality.put("very fine", price3); // 3rd element is added
Float price4 = new Float(1.00F); // if the book is fine, the price is the same as the base price
quality.put("fine", price4); // the 4th element is added
Float price5 = new Float(0.50F); // if the book is good, the price will be half of the base price
quality.put("good", price5); // the 5th element is added
Float price6 = new Float(0.25F); // if the book is poor, the price is quarter of the base price
quality.put("poor", price6); // the 6th element is added
Comic[] comics = new Comic[3]; // create a new array with three comics in it
comics[0] = new Comic("Amazing Spider-Man", "1A", "very fine", 5400.00F);
// the first element of the comic array is added
comics[0].setPrice((float)quality.get(comics[0].condition));
// set the final price of the first book
comics[1] = new Comic("Incredible Hult", "181", "near mint", 770.00F);
// the first element of the comic array is added
comics[1].setPrice((float)quality.get(comics[1].condition));
// set the final price of the first book
comics[2] = new Comic("Cerebus", "1A", "good", 260.00F);
// the first element of the comic array is added
comics[2].setPrice((float)quality.get(comics[2].condition));
// set the final price of the first book
for (int i = 0; i < comics.length; i++) {
System.out.println("Title: " + comics[i].title + ";");
// to print the title of the book
System.out.println("Issue number: " + comics[i].issueNumber + ";");
// to print the issue number of the book
System.out.println("Condition: " + comics[i].condition + ";");
// to print the condition of the book
//System.out.println("Price: $" + comics[i].price + "; \n");//比较下,就是这块空格的问题,可能是中文下的空格
System.out.println("Price:$"+comics[i].price + "; \n");
// to print the final price of the book
}
}
public class Comic {
String title; // the title of the book
String issueNumber; // the issue number of the book
String condition; // the condition of the book
float basePrice; // the base price of the book
float price; // the actual price of the book
Comic(String inTitle, String inIssueNumber, String inCondition, Float inBasePrice) {
// the constructor for the 'Comic'
title = inTitle; // set the book's title as the input title
issueNumber = inIssueNumber; // set the book's issue number as the input one
condition = inCondition; // set the book's condition as the input one
basePrice = inBasePrice; // set the book's base price as the input one
}
void setPrice(Float factor) { // a function to set the final price of the book
float multiplier = factor.floatValue(); // transfer 'factor' to another float number
price = basePrice * multiplier; // set the final price for the book
}
}}
你把“Price $” + 这里加号前后的空格删了就对了