Wijitmaker Posted April 30, 2004 Report Share Posted April 30, 2004 Just finished my second java homework assignment. Wahooo! Tell me what you think!?Note: it assumes some user intellegence on inputimport java.io.*; //calling all classes in the java.io file in the java directoryimport java.text.DecimalFormat;public class Video{ public static void main (String [] arguements) throws IOException {/****************************************************************************** Name: Jason Bishop* Program: Video* Description: Simulation of a video store cash register* References: None*****************************************************************************/ BufferedReader kb = new BufferedReader (new InputStreamReader(System.in)); //calling up classes from the java.io file we imported DecimalFormat money = new DecimalFormat("'$'#.00"); //setting a money format, note I figured out how to autimatically include the dollar sign/*******************************INPUT SESSION********************************/ final String Pad1 = " "; // setting a pad of 26 spaces final String Pad2 = " "; //setting a pad of 16 spaces System.out.print("Please enter your name: "); // asking for name input String name = kb.readLine(); System.out.println(""); System.out.println("Now enter your rental information for video rental #1"); System.out.println(""); System.out.print("Title: "); //asking for title input String title1 = (kb.readLine() + Pad1).substring(0,26); //decided to pad this up here, instead of waiting to do it below System.out.print("Type (n = New, o = Old, c = Classic): "); String type1 = kb.readLine(); type1.toLowerCase(); //setting to lowercase to minimize input errors System.out.print("Days rented? "); String rent1 = kb.readLine(); // This is a copy of the form for video rental #1 above (except I changed all 1's to 2's) System.out.println(""); System.out.println("Now Enter your rental information for video rental #2"); System.out.println(""); System.out.print("Title: "); String title2 = (kb.readLine() + Pad1).substring(0,26); System.out.print("Type (n = New, o = Old, c = Classic): "); String type2 = kb.readLine(); System.out.print("Days rented? "); String rent2 = kb.readLine(); System.out.println("");/*************************USER INPUT INTERPRITATION**************************/ int rent1int = Integer.parseInt(rent1); //changing a string entry to an interger for calcuations int rent2int = Integer.parseInt(rent2); double cost1 = 0.0; //setting a place holder for a movie cost value String type1full = "error"; //setting a place holder for the string output of the movie type if (type1.equalsIgnoreCase("c")) {cost1 = .598; type1full = "Classic";} else if(type1.equalsIgnoreCase("o")) {cost1 = .998; type1full = "Old";} else if(type1.equalsIgnoreCase("n")) {cost1 = 2.495; type1full = "New";} //next few lines are a repeat from above double cost2 = 0.0; String type2full = "error"; if (type2.equalsIgnoreCase("c")) {cost2 = .598; type2full = "Classic";} else if(type2.equalsIgnoreCase("o")) {cost2 = .998; type2full = "Old";} else if(type2.equalsIgnoreCase("n")) {cost2 = 2.495; type2full = "New";} double rentcost1 = cost1 * rent1int; //multiplying daily cost by days rented double rentcost2 = cost2 * rent2int; if (rentcost1 > 99.00) rentcost1 = 99.00; //caps the cost per video at 99.00 max if (rentcost2 > 99.00) rentcost2 = 99.00; double tax = (rentcost1 + rentcost2) * .081; //calculating the tax cost double total = rentcost1 + rentcost2 + tax; //adding the tax cost to the video cost String cost1output = money.format(rentcost1); //applying the money format to the doubles and creating new string variables String cost2output = money.format(rentcost2); String taxoutput = money.format(tax); String totaloutput = money.format(total);/******************************OUTPUT SESSION********************************/ System.out.println("Your Recipt:"); System.out.println(""); System.out.println("STUDENT NAME: " + name); String cell_a1 = ("VIDEO NAME" + Pad1).substring(0,26); //padding the 'cell' to the right String cell_a2 = ("TYPE" + Pad2).substring(0,16); String cell_a3 = ("DAYS RENTED" + Pad2).substring(0,16); String cell_a4 = ("COST OF VIDEO" + Pad2).substring(0,16); String cell_b2 = (type1full + Pad2).substring(0,16); String cell_b3 = (Pad2 + rent1).substring(rent1.length(),16 + rent1.length()); //padding the cell to the left (note: I found it easier to take the length of the string as the minimum and the length of the string plus the pad as the maximum) String cell_b4 = (Pad2 + cost1output).substring(cost1output.length(),16 + cost1output.length()); String cell_c2 = (type2full + Pad2).substring(0,16); String cell_c3 = (Pad2 + rent2).substring(rent2.length(),16 + rent2.length()); String cell_c4 = (Pad2 + cost2output).substring(cost2output.length(),16 + cost2output.length()); String cell_d3 = ("TAX:" + Pad2).substring(0,16); String cell_d4 = (Pad2 + taxoutput).substring(taxoutput.length(),16 + taxoutput.length()); String cell_e3 = ("TOTAL DUE:" + Pad2).substring(0,16); String cell_e4 = (Pad2 + totaloutput).substring(totaloutput.length(),16 + totaloutput.length()); System.out.println("@" + "--------------------------" + "-" + "----------------" + "-" + "----------------" + "-" + "----------------" + "@"); System.out.println("|" + cell_a1 + "|" + cell_a2 + "|" + cell_a3 + "|" + cell_a4 + "|"); System.out.println("|" + "--------------------------" + "|" + "----------------" + "|" + "----------------" + "|" + "----------------" + "|"); System.out.println("|" + title1 + "|" + cell_b2 + "|" + cell_b3 + "|" + cell_b4 + "|"); System.out.println("|" + "--------------------------" + "|" + "----------------" + "|" + "----------------" + "|" + "----------------" + "|"); System.out.println("|" + title2 + "|" + cell_c2 + "|" + cell_c3 + "|" + cell_c4 + "|"); System.out.println("|" + "--------------------------" + "-" + "----------------" + "|" + "----------------" + "|" + "----------------" + "|"); System.out.println("|" + Pad1 + " " + Pad2 + "|" + cell_d3 + "|" + cell_d4 + "|"); System.out.println("|" + Pad1 + " " + Pad2 + "|" + "----------------" + "|" + "----------------" + "|"); System.out.println("|" + Pad1 + " " + Pad2 + "|" + cell_e3 + "|" + cell_e4 + "|"); System.out.println("@" + "--------------------------" + "-" + "----------------" + "-" + "----------------" + "-" + "----------------" + "@"); }//end of main}//end of Video Class Quote Link to comment Share on other sites More sharing options...
Mystic-Al-Bob Posted May 1, 2004 Report Share Posted May 1, 2004 looks intersting but I haven't finished reading everything yet Quote Link to comment Share on other sites More sharing options...
Argalius Posted May 3, 2004 Report Share Posted May 3, 2004 Looks very ... ... interesting I've no idea what it does Quote Link to comment Share on other sites More sharing options...
King Tutankhamun Posted May 3, 2004 Report Share Posted May 3, 2004 That is cool that you have a Java class. I was thinking of taking a programming course as well some time. Quote Link to comment Share on other sites More sharing options...
pinkisacolor Posted May 8, 2004 Report Share Posted May 8, 2004 That is cool that you have a Java class. I was thinking of taking a programming course as well some time. me too...but the closest thing that our school has to technology is making lego robots Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.