Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: New to Java Can not figure out how to create a table with my codes outputs!

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation New to Java Can not figure out how to create a table with my codes outputs!

    It is my final project for my university and it was a 101 course. I can not figure out how to create a table that will represent the price with the discount but before shipping charges and taxes. My current code is
    package assignment3;


    public class DataEquations {
     
        private int ItemsPurchased; // first number to add
        private double ItemWeight; // second number to add
        private double PricePerPound = 3.00; // sum of number1 and number2
        private double taxrate = .01; // Tax Rate
        private double Discount;
        private double VariablePrice;
     
        public DataEquations() {
        }
     
        public DataEquations(int Items, double Weight) {
            ItemsPurchased = Items;
            ItemWeight = Weight;
        }
     
        public void setItems(int Items) {
            ItemsPurchased = Items;
        }
     
        public void setWeight(double Weight) {
            ItemWeight = Weight;
        }
     
        public int getItems() {
            return ItemsPurchased;
        }
     
        public double getWeight() {
            return ItemWeight;
        }
     
        public double getPriceBeforeTaxes() {
            return ItemsPurchased * ItemWeight * PricePerPound;
        }
     
        public double getPriceAfterTaxes() {
            return ((getPriceBeforeTaxes() * getDiscount())  + getShipPrice() + getBoxPrice()) * (1 +getTax());
     
     
        }
        public double getTotalWeight(){
            return ItemsPurchased * ItemWeight;
        }
     
        public double getTax(){
            return (taxrate);
        }
     
        public double getDiscount() {
            if (ItemsPurchased >= 25 & (ItemsPurchased < 50)){
                Discount = 1 - .05;
            } else if (ItemsPurchased >= 50 & (ItemsPurchased < 100)) {
                Discount = 1 - .10;
            } else if (ItemsPurchased >= 100 & (ItemsPurchased < 200)) {
                Discount = 1 - .15;
            } else if (ItemsPurchased >= 200 & (ItemsPurchased < 500)) {
                Discount = 1 - .20;
            } else if (ItemsPurchased >= 500& (ItemsPurchased < 1000)) {
                Discount = 1 - .25;
            } else if (ItemsPurchased >= 1000) {
                Discount = 1 - .30;
     
            } else if (ItemsPurchased < 25)
                    Discount = 1;
            return Discount;
        }
     
            public double getShipPrice(){
            if (getTotalWeight() >= 0 & (getTotalWeight() < 10)){
                VariablePrice = 2.00;
            } else if (getTotalWeight() >= 10 & (getTotalWeight() < 50)) {
                VariablePrice = 4.00;
            } else if (getTotalWeight() >= 50 & (getTotalWeight() < 100)) {
                VariablePrice = 8.00;
            } else if (getTotalWeight() >= 100 & (getTotalWeight() < 500)) {
                VariablePrice = 12.00;
            } else if (getTotalWeight() >= 500& (getTotalWeight() < 1000)) {
                VariablePrice = 20.00;
            } else if (getTotalWeight() >= 1000) {
                VariablePrice = 30.00;
     } 
            return VariablePrice + 2.95;
     
        }
            public double getBoxPrice() {
                return getTotalWeight() / 10  * 2 ;
            }
     public int getBoxes() {
         int Boxes = (int)(getTotalWeight() / 10 + .9999);
         return Boxes;
     }
    }
     
     
     
     
     
    package assignment3;
     
    import java.util.Scanner;
     
    public class PriceCalculator {
     
     
        public static void main(String[] args) {
     
            Scanner input = new Scanner( System.in );
           DataEquations price = new DataEquations();
     
           System.out.print( "Enter Number of Items Purchased: " ); // prompt
          int Items = input.nextInt(); // read first number from user
          price.setItems(Items);
     
          System.out.print( "Enter Weight of Items: " ); // prompt
          double Weight = input.nextDouble(); // read second number from user
          price.setWeight(Weight);
            System.out.printf("Base Price = $%.2f\n", price.getPriceBeforeTaxes());
     
            System.out.printf("Discount = $%.2f\n", price.getPriceBeforeTaxes() * (1- price.getDiscount()));
     
            System.out.printf("Base Price Including Discount = $%.2f\n", price.getPriceBeforeTaxes() * price.getDiscount());
     
            System.out.printf("Ship Price = $%.2f\n", price.getShipPrice());
     
            System.out.printf("Base Price With Discount and Ship Price = $%.2f\n", price.getPriceBeforeTaxes() * price.getDiscount() + price.getShipPrice());
     
            System.out.printf("Number of Boxes Needed = %d\n", price.getBoxes());
     
            System.out.printf("Box Price = $%.2f\n", price.getBoxPrice());
     
          System.out.printf("Subtotal = $%.2f\n", price.getPriceBeforeTaxes() * price.getDiscount() + price.getShipPrice() + price.getBoxPrice());
     
          System.out.printf("Tax on Purchase = $%.2f\n", (price.getPriceBeforeTaxes() * price.getDiscount() + price.getShipPrice() + price.getBoxPrice()) * price.getTax());
     
          System.out.printf("Total Price = $%.2f\n", price.getPriceAfterTaxes());
     
     
     
        }
    }
    Thanks for all the help!

    ps. the table's rows should represent the number of items sold, and the columns are the weight of items in pounds
    Last edited by shoppa028; May 11th, 2011 at 03:07 PM. Reason: added [CODE]


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,662
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: New to Java Can not figure out how to create a table with my codes outputs!

    I'm not sure I understand what your problem is.
    Do you know what the contents of the table are and don't know how to output the data?
    Is the output to be printed on a console screen using print or how are you going to display it?
    Can you create a sample output using pencil and paper so you know what goes in each row and column?
    ps. the table's rows should represent the number of items sold, and the columns are the weight of items in pounds
    Can you enter some data showing what you mean here? This doesn't make any sense to me.

Similar Threads

  1. Java Based lightweight Table (grid)
    By vairam in forum Member Introductions
    Replies: 5
    Last Post: April 11th, 2011, 06:13 AM
  2. how to import excel file to database table using java
    By palani in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 3rd, 2010, 12:17 AM
  3. Create table statement from DatabaseMetaData
    By sid7 in forum JDBC & Databases
    Replies: 6
    Last Post: August 28th, 2010, 01:23 PM
  4. Replies: 0
    Last Post: April 15th, 2010, 05:13 AM
  5. Urgent Help needed with java codes
    By makarov in forum Java Theory & Questions
    Replies: 0
    Last Post: November 13th, 2009, 06:23 AM