无论如何,我几乎不理解作业,我会说实话。真的是自由球,但我已经把它归结为:
import java.util.Scanner;
import java.text.DecimalFormat;
public class TimeTravel
{
static final double STUDENT_DISCOUNT = .50;
static final double EMPLOYEE_DISCOUNT = .25;
/**
* Discounts described
*
* @param args Command line arguments (not used).
*/
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
//double ticketcode;
System.out.println("Enter ticketcode: ");
//ticketcode = userInput.nextDouble();
Scanner input = new Scanner(System.in);
String ticketcode = input.nextLine();
System.out.println((char)Integer.parseInt(ticketcode));
int tcode = Integer.parseInt(ticketcode);
//String s = Double.toString(ticketcode);
if (tcode <= 26) {
System.out.println("*** Invalid ticket code ***"
+ "\nTicket code must have at least 26 characters.");
}
else {
System.out.println("Time: ");
System.out.println(ticketcode.substring(0, 4));
System.out.println("Date: ");
System.out.println(ticketcode.substring(5, 12));
System.out.println("Category: ");
System.out.println(ticketcode.substring(0, 4));
System.out.println("Seat: ");
System.out.println(ticketcode.substring(27, 29));
System.out.println("Itinerary: ");
System.out.println(ticketcode.substring(30, 54));
double price = Double.parseDouble(ticketcode);
DecimalFormat df = new DecimalFormat("#,###.00");
System.out.println("Price: " + df.format((ticketcode.substring(14, 22))));
System.out.println(ticketcode.substring(0, 4));
System.out.println("Cost: ");
System.out.println("Prize Number: ");
System.out.println(ticketcode.substring(0, 4));
}
}
}
主体内的每一条评论都是我的漫无边际。
答案 0 :(得分:0)
如果插入标准输入(在您的情况下为ticketcode
)非整数字符,则Integer.parseInt(ticketcode)
将抛出NumberFormatException
。这是因为无法解析非整数输入。