Wednesday 15 August 2012

java - Calling a calculated variable from a class -


I have a little problem with this practice and I was thinking that anyone can help. Here's the problem:

Create a class named Purchase. Each purchase includes an invoice number, amount of sales and sales tax volume. Include the invoice number and the prescribed methods for the sale amount, within the set () method for sale amount, sales tax of 5% of the sale amount. Calculate Also include a demonstration method that shows the details of the purchase. Save as purchase. Create an application that declares a purchase object and prompts the user for purchase details. When you point to an invoice number, do not let the user move forward until a number between 1,000 and 8,000 is entered. When you point to a sales amount, proceed until the user has entered an illegal value. Created after the valid purchase object, display the object's invoice number, sales amount, and sales tax.

Here is my code for my shopping class

  import javax.swing.JOptionPane; Import java.util.Scanner; Public category purchase {// variables public static int invoice; Public static double salesmount; Public stable double sales tax; // Invoice public waste set invoice (int x) {invoice = x; } Get public int () {return invoice; } // Set For Sale & amp; Set Amount Public Zero SetSaleAmount (double y) {saleTax = y * 0.05; SaleAmount = y; } Public Double Mill Amount () {Return Sales Amount; } // Get the Texas Texas Public Double Saltex (for Sale) {Return Sales Tax; } // Display method Public zero display (int invoice, double cell account, double letter tex) {System.out.println ("Invoice number:" + + + "+ + \" '' Sale amount: "+ + Sale account + '\ N' + "Sales Tax:" + Sales Tax); }}   

and code for the CreatePurchase class

  import javax.swing.JOptionPane; Import java.util.Scanner; Make Public CategoryPurchase {Public Static Zero Main (String [] Args) {Purchase Purchase 1 = New Purchase (); // Scanner zodiac scanner for sale inputDevice = new scanner (System.in); System.out.println ("Please enter the sales amount:"); Purchase. Amazon = InputDiva NXD double (); // While loop amounts for sale (Purchase Solium & lt; 1) {System.out.print ('\ n' + "error, your sales amount needs to be more than 0. Please enter a valid sale amount: Gt; & gt; "); Purchase. Amazon = InputDiva NXD double (); } // Invoice System.out.println ("Please enter an invoice number between 1000 and 8000"); Purchase.invoice = inputDevice.nextInt (); // Loop for invoices (Purchase.invoice & lt; 999 || Purchase.invoice & gt; 8000) {System.out.print ('\ n' + "Error, enter a valid invoice number between 1000 and 8000 : & Gt; & gt; "); Purchase.invoice = inputDevice.nextInt (); } // display results. Joppenpen Show Message Dialege (empty, "Your invoice number is" + Purchase.invoice + '\ n' + "Your sales tax is:" + purchase.Siltex + '\ n' + "Your total is:" + Purchase Sol Amount ); }}   

As you can see, when you run second class, the additional 5% of sales are not left as 0 in sales tax and sales tax . Is it really something really silly, but I do not know where to start from.

Definition of invoices, sales, and sales public static object-oriented programming Deletes the purpose.

They should be a personal instance variables, and you should access and modify them by receiving and receiving set-up methods on these examples ( purchase1 ). Otherwise there is no point in defining those setters and gates, and there is no point in making this example, which you never used.

No comments:

Post a Comment