SpaceTicket.java
import java.util.Random;
import java.util.Scanner;
public class SpaceTicket {
private static final double STUDENT_DISCOUNT = 0.25;
private static final double CHILD_DISCOUNT = 0.35;
public static void main(String[]args)
{
System.out.print("Enter ticket code: ");
Scanner sc = new Scanner(System.in);
String code = sc.nextLine().trim();
// checking whether the ticket code has at least 25
characters
if(code.length() < 25)
{
System.out.println("\n*** Invalid ticket code ***\nTicket code must
have at least 25 characters.\n");
System.exit(0);
}
// assuming price always has 8 digits; 9 because substring excludes
the end index
String price = code.substring(0, 8);
double ticketPrice = Double.parseDouble(price.substring(0, 6) + "."
+ price.substring(6));
// now extracting the category and applying the discount
char category = code.charAt(8);
double cost = 0;
switch(category)
{
case 's':
cost = ticketPrice - (STUDENT_DISCOUNT * ticketPrice);
break;
case 'c':
cost = ticketPrice - (CHILD_DISCOUNT * ticketPrice);
break;
default:
cost = ticketPrice;
break;
}
// extracting the time
String time = code.substring(9, 11) + ":" + code.substring(11,
13);
// extracting the date
String date = code.substring(13, 15) + "/" + code.substring(15, 17)
+ "/" + code.substring(17, 21);
// extracting the seat number
String seatNumber = code.substring(21, 24);
// extracting the ticket description
String ticketDesc = code.substring(24);
// generating the prize number
Random rand = new Random();
int prize = rand.nextInt(999999) + 1;
String prizeNum = String.valueOf(prize);
int padding = 0;
String zeros = "";
if(prizeNum.length() < 6)
padding = 6 - prizeNum.length();
for(int i = 0; i < padding; i++)
{
zeros += "0";
}
prizeNum = zeros + prizeNum;
/* DISPLAYING ALL THE DETAILS */
System.out.println("\nSpace Ticket: " + ticketDesc);
System.out.println("Date: " + date + "\tTime: " + time + "\tSeat: "
+ seatNumber);
System.out.println("Price: $" + String.format("%,.2f", ticketPrice)
+ "\tCategory: " + category + "\tCost: $"
+ String.format("%,.2f", cost));
System.out.println("Prize Number: " + prizeNum + "\n");
}
}
******************************************************************* SCREENSHOT ********************************************************
Project: Using Java API Classes Page 3 of 5 SpaceTicket.java Requirements: The purpose of this program is accept coded...
For this program, you will be working with data from the NASA website which lists Near Earth Objects detected by the JPL Sentry System. You are given a text file listing the designation and impact probability (with Earth, generally within the next 100 years) of 585 Near Earth Objects. Your job will be to sort these objects by their impact probabilities. Input File Format The input file contains 585 records. Each record is on a separate line. Each line contains...
Modify When executing on the command line having only this program name, the program will accept keyboard input and display such until the user does control+break to exit the program. The new code should within only this case situation “if (argc == 1){ /* no args; copy standard input */” Replace line #20 “filecopy(stdin, stdout);” with your new code. Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the command line to be tested...
GENERAL INSTRUCTIONS All requirements specified on page 64-67 of the course packet “2.5 Programming Assignment Submission Requirements” and “2.6 Flow Chart Symbols” should be followed. Plan the programs on paper before you attempt to write any programs (it will take less time to complete the assignment overall). Electronic version of your programs (the .m files you create) must be uploaded to Canvas. Attach multiple files to one submission. All files must be received by the beginning of...
Help Please on JAVA Project: Validating the input is where I need help. Thank you Requirements description: Assume you work part-time at a sandwich store. As the only employee who knows java programming, you help to write a sandwich ordering application for the store. The following is a brief requirement description with some sample output. 1. Selecting bread When the program starts, it first shows a list/menu of sandwich breads and their prices, then asks a user to select a...
Assignment You will be developing a speeding ticket fee calculator. This program will ask for a ticket file, which is produced by a central police database, and your program will output to a file or to the console depending on the command line arguments. Furthermore, your program will restrict the output to the starting and ending dates given by the user. The ticket fee is calculated using four multipliers, depending on the type of road the ticket was issued: Interstate...
Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1. The input and variable value file are both text files that will be specified in...
Please use Java to write the program The purpose of this lab is to practice using inheritance and polymorphism. We need a set of classes for an Insurance company. Insurance companies offer many different types of policies: car, homeowners, flood, earthquake, health, etc. Insurance policies have a lot of data and behavior in common. But they also have differences. You want to build each insurance policy class so that you can reuse as much code as possible. Avoid duplicating code....
Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....
Project 3 Objective: The purpose of this lab project is to exposes you to using menus, selection writing precise functions and working with project leaders. Problem Specification: The PCCC Palace Hotel needs a program to compute and prints a statement of charges for customers. The software designer provided you with the included C++ source and you are asked to complete the code to make a working program using the given logic. The function main () should not change at all....
Writing Unix Utilities in C (not C++ or C#) my-cat The program my-cat is a simple program. Generally, it reads a file as specified by the user and prints its contents. A typical usage is as follows, in which the user wants to see the contents of my-cat.c, and thus types: prompt> ./my-cat my-cat.c #include <stdio.h> ... As shown, my-cat reads the file my-cat.c and prints out its contents. The "./" before the my-cat above is a UNIX thing; it...