please improve this coding and correct this coding if there is an error. This system was developed
Question:
please improve this coding and correct this coding if there is an error.
This system was developed to make a booking bus ticket system in Malaysia easier since the currently used manual system is using manpower and is having some difficulties and quite problematic to handle a lot of customers at once when it comes to holiday celebrations or public holidays. Hence, we developed a system named "BusTicket" to make sure people have a functioning operating system while booking tickets. The system can be used by customers and will display all the details while the system will make sure the input that has been key in is accurate so the system does not have any particular reason to reject or postpone their booking. This system is expected to operate smoothly, accommodating and is a user friendly structure.
import java.util.Scanner; public class BusBookingSystem { public static void main(String[] angs){ Scanner in=new Scanner(System.in); Scanner inLine=new Scanner (System.in); System.out.println("---------------------------------------------"); System.out.println("\t Welcome to Bus Booking Ticket System. " +" \tBook your Bus Ticket with us!" +" \tHere is the Destinations Available:"); System.out.println(); System.out.println("(A)-(Kedah,Perlis,Pulau Pinang and Perak) / RM45" +" (B)-(Selangor, Wilayah Persekutuan Kuala Lumpur and Putrajaya) / RM62" +" (C)-(Negeri Sembilan, Melaka and Johor) / RM49.5" +" (D)-(Kelantan, Terengganu and Pahang) / RM53.2"); System.out.println(); System.out.println(" You will be Charged For discount for: " + " 1) Age below 12 years old. 50%"+" 2) Age between 13 - 18 years old 60%" +" 3) Age above 60 70%"); System.out.println(); System.out.println("Tax fee : Malaysian Citizen RM10 Non-Malaysian RM25"); System.out.println("---------------------------------------------"); System.out.println(); System.out.print(" Enter your Name: "); String a = in.nextLine(); System.out.print(" Enter your Age: "); int b = in.nextInt (); System.out.print(" Enter Your Destination(Using the given code):"); char c = in.next().charAt(0); System.out.print("A Malaysian Citizen? (True/False): "); boolean d = in.nextBoolean(); System.out.println(); System.out.println(); //create new object Processor ps = new Processor(a,b,c,d); ps.getName(); ps.getAge(); ps.getDestination(); ps.getCitizen(); ps.whichPrice(); ps.discount(); ps.decideTax(); ps.totalPrice(); //print out printr method System.out.println(ps.displayTicket()); } }
public class Processor { private String name; private int age; private char destination; private boolean citizen; public double discount = 0.0; public double tax = 25.0; private double price; public double totalPrice; // normal constructor public Processor(String a, int b, char c, boolean d) { name = a; age = b; destination = c; citizen = d; } // mutator method for attributes public String getName() { return name; } public int getAge() { return age; } public char getDestination() { return destination; } public boolean getCitizen() { return citizen; } //processor methods to calculate price public double whichPrice() { if (getDestination() == 'A' || getDestination() == 'a') { price = 45.0; } else if (getDestination() == 'B' || getDestination() == 'b') { price = 62.0; } else if (getDestination() == 'C' || getDestination() == 'c') { price = 49.5; } else if (getDestination() == 'D' || getDestination() == 'd') { price = 53.2; } return price; } //calculate discount public double discount() { if (getAge() <= 12) { discount = 0.3 * whichPrice(); } else if (getAge() >= 13 && getAge() <= 18) { discount = 0.2 * whichPrice(); } else if (getAge() >= 60) { discount = 0.5 * whichPrice(); } else { discount = discount; } return discount; } //calculate tax public double decideTax() { if (getCitizen() == citizen) { tax = 10.0; } return tax; } //calculate total price public double totalPrice() { return totalPrice = whichPrice() - discount() + decideTax(); } // output display ticket public String displayTicket() { String ticket = " \t==================================================" + " \tHere is your Ticket. " + " \tName: " +this.getName() + " \tAge: " +this.getAge() + " \tDestination : " + this.getDestination() + " \tDiscount : RM" + this.discount() + " \tTax Charged : RM" + this.decideTax() + " \t--------------------------------------------------" + " \tYour ticket price : RM" + totalPrice() + " \tHave a decent ride." + " \t=================================================="; return ticket ; } }
Accounting Principles Part 1
ISBN: 978-1118306789
6th Canadian edition
Authors: Jerry J. Weygandt, Donald E. Kieso, Paul D. Kimmel, Barbara Trenholm, Valerie Kinnear, Joan E. Barlow