Results 1 to 2 of 2
  1. #1
    Boomer1 is offline Member
    Join Date
    Oct 2009
    Posts
    20
    Rep Power
    0

    Question Calling a class and a little confused

    Hello, I am stuck here on an application...basically I am to set up a cash register and my first class is compiling correctly, however, when I try to call it...I believe I am missing something here. Can someone please point me in the right direction please? Or tell me where I should concentrate on?

    Thank you so much

    public class Register
    {

    //data fields
    private double subTotal;
    private final double SALES_TAX = .075;
    private double total;
    private double change;
    private double salesTax;
    private double cashPaid;
    private int Item;
    double Cost;
    int Quantity;

    //constructors

    public void CashRegister()
    {

    int twentyBills = 2;
    int tenBills = 2;
    int fiveBills = 2;
    int quarters = 8;
    int dimes = 20;
    int nickels = 40;
    int pennies = 50;


    }//End constructors

    //Set and Get Methods for Item
    public void setItem(int items)
    {
    Item = items;
    }

    public int getItem()
    {
    return Item;
    }//End Set and Get Item

    //Set and Get Methods for quantity
    public void setQuantity(int quan)
    {
    Quantity = quan;
    }

    public int getQuantity()
    {
    return Quantity;
    }//End Set and Get quantity

    //Set and Get for Price
    public void setCost(double price)
    {
    Cost = price;
    }

    public double getCost()
    {
    return Cost;
    }//End Set and Get quantity




    public void subTotal()
    {
    subTotal = Quantity * Cost;
    }

    public void SALEX_TAX()
    {
    salesTax = subTotal * SALES_TAX;
    }

    public void total()
    {
    total = subTotal + salesTax;
    }

    public void change()
    {
    change = cashPaid - total;
    }

    public void displayReceipt()
    {
    System.out.println("Item bought was " + Item);

    System.out.println();
    System.out.println("Sub total is " + subTotal);
    System.out.println("Tax 7.5% of sub total is " + salesTax);
    System.out.println("Cash paid is " + cashPaid);
    System.out.println("Change given back is " + change);

    }

    }//End Class









    public class TestRegister
    {
    public static void main(String [] args)
    {

    Register myRegister = new Register( );
    //Get user input

    Scanner keyboard = new Scanner(System.in);
    System.out.print("What item would you like to purchase? Press 1 for socks, 2 for towel, or 3 for razor ");
    Item = keyboard.nextLine();

    System.out.print("How many would you like to purchase?");
    Quantity = keyboard.nextInt();

    System.out.print("What is the price?");
    Cost = keyboard.nextDouble();



    myRegister.displayMessage();
    }//End Main
    }//End Class

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    yeah, you're missing a lot:
    Java Code:
    Item = keyboard.nextLine();
    
    System.out.print("How many would you like to purchase?");
    Quantity = keyboard.nextInt();
    
    System.out.print("What is the price?");
    Cost = keyboard.nextDouble();
    
    myRegister.displayMessage();
    You didn't declare data types for Item, Quantity and Cost, (and they should be lowercase fyi :), and then you don't do anything with them. Yes you created an instance of Register, but you never give it any of the data you just collected -- so it has nothing to print. Finally, your Register class has no 'displayMessage()' method, so calling it wont work.

Similar Threads

  1. Child-Class Calling a Method in a Parent-Class
    By Blah_ in forum New To Java
    Replies: 5
    Last Post: 09-29-2009, 03:48 AM
  2. Calling a class method from another class
    By caro in forum New To Java
    Replies: 4
    Last Post: 06-10-2009, 02:12 AM
  3. problem calling function from class to class
    By alin_ms in forum New To Java
    Replies: 3
    Last Post: 12-19-2008, 08:35 PM
  4. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 01:25 AM
  5. Yet another Wrapper Class confused guy.
    By JAdeline in forum New To Java
    Replies: 2
    Last Post: 08-15-2008, 05:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •