Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: java assignment

  1. #1
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default java assignment

    I am doing a java assignment and I ahve a problem when I call class from antoher class.. can someone help me pls?

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: java assignment

    And your problem is?

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    Yes, we're waiting for you to explain your problem and show the code.
    Please wrap your code in code tags when posting it.
    Wrap your code with[code]<YOUR CODE HERE>[/code] to get highlighting

  4. #4
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    i have three Classes Product,Client and Display. i want Product and Client in the Display.. how can i do it?

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    Is this a quesition about the GUI display?
    If the Display class extends the Container class and the Product and Client classes extend the Component class, then you can call
    the Container class's add method.

    Otherwise please explain what "in the" means.
    Do you want inner classes? The two classes' definitions are in the source for the other class.

  6. #6
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    THE QUESTION IS :

    INPUT
    (1) The customer’s name and their address.
    (2) How many of each type of hardware item the customer wants to purchase.
    OUTPUT
    The program should print out on the screen an invoice for the customer’s order, consisting of:
    (1) The customer’s name and address.
    (2) One or more order lines, each of which consists of
    Product Code, Product description, quantity ordered, unit price, total price.
    (3) Grand total of the order lines.
    (4) Final price, including 20% VAT (Value-Added Tax) plus $1.00 per item shipping cost.
    An example of a typical run of your program might look like this, with user’s input in bold:

    HARDWARE ITEMS
    CODE DESCRIPTION UNIT PRICE
    K16 Wood screws, brass, 20mm, pack of 50 $ 7.75
    D24 Wood glue, clear, 1 litre $ 5.50
    M93 Sandpaper, medium grade, 100 sheets $10.25
    M94 Sandpaper, fine grade, 100 sheets $14.75
    PLACE YOUR ORDER!
    NAME: Bill Silic
    ADDRESS-1: Apt 23
    ADDRESS-2: Building 8
    ADDRESS-3: Winchester
    CODE: 89763
    ENTER CODE (XX to Stop):
    CODE: D24
    QUANTITY: 2
    CODE: K16
    QUANTITY: 1
    CODE:XX
    INVOICE FOR ORDER
    Bill Silic
    Apt 23
    Building 8
    Winchester POST CODE: 89763

    D24 Wood glue, clear, 1 litre 2 @ $ 5.50 $ 11.00
    K16 Wood screws, brass, 20mm, pack of 50 1 @ $ 7.75 $ 7.75
    TOTAL: $ 18.75
    Shipping: 2 items @ 1.00 2.00
    TOTAL INCL. SHIPPING: 20.75
    VAT at 20% 4.15
    TOTAL TO PAY: 24.90

  7. #7
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    i have done the product and the client class with the array and now i want them in my main class

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    Please explain what you mean by "want them in"?
    Most classes make use of other classes.
    One commonly used class is the String class. It is "used in" most classes.
    How does your requirement differ from the use of the String class in your class?

  9. #9
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    i want the output of the two classes be in the output of the third classs

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    What is the output?
    Strings written to a console?
    Bytes written to a file?

    Do the two classes have methods you call that return the output in an object
    or how do the classes do the output directly and their methods do not return anything?

  11. #11
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    how can i use the one ex: client myclient = my client ... ?

  12. #12
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    can i send you my assignment?

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    Please post the code here that you are having problems with.
    Or make a small simple program that shows the problem.

  14. #14
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    FIRST CLASS
    Java Code:
    import java.util.*;
    import java.text.*;
    
    
    
    public class Business{
    public static void main(String []args)
    
     {
    
      Scanner in=new Scanner(System.in);
    
      double total=0;
    
      ArrayList<Product> list=new ArrayList<Product>();
      list.add(new Product("K16" ,"Wood screws,brass,20mm", 7.75));
      list.add(new Product("D24","Wood glue,clear,1 liter",5.50));
      list.add(new Product("M93","Sandpaper,fine grade",10.25));
      list.add(new Product("M94","Sandpaper,fine grade",14.75));
      DecimalFormat df=new DecimalFormat("$ ##.##");
    
    
    
    System.out.println("Hardware Items");
    System.out.println();
    System.out.println("Code " + " " +" Description " + " " +" Unit Price ");
    
    
    
          for(Product e : list){
    
          System.out.println(e.getCode () + "\t" + e.getDescription() + "\t" + df.format (e.getPrice ()) );
    
          }
    
          }
    
          }
    
    ==================================================================
    
    SECOND CLASS
    
    import java.util.*;
    import java.text.*;
    
    
    
    public class Details{
    public static void main(String []args)
    
     {
    
      Scanner in=new Scanner(System.in);
    
      ArrayList<Client> list=new ArrayList<Client>();
      list.add(new Client("Morgan"));
      list.add(new Client("Cassia"));
      list.add(new Client("Mayson Ville"));
      list.add(new Client("Oxford Street"));
      list.add(new Client("London"));
      list.add(new Client("LND"));
    
    
    
    
    System.out.println("PLACE YOUR ORDER!");
    System.out.println();
    System.out.println("Name " + " ");
    System.out.println("Surname " + " ");
    System.out.println("Address_1 " + " ");
    System.out.println("Address_2 " + " ");
    System.out.println("Address_3 " + " ");
    System.out.println("Postcode" + " ");
    
    
    
    
          for(Client e : list){
    
    System.out.println(e.getName () + "\t" + e.getSurname() + "\t" + e.getAddress_1() + "\t" + e.getAddress_2()+ "\t" + e.getAddress_3()+ "\t" + e.getPostcode());
    
          }
    System.out.println("Enter Code (XX to stop)" );
    
    System.out.print("Code:" );
    
    String code=in.next();
    
    System.out.print("Quantity: ");
    
    int quantity=in.nextInt();
    
    while(!code.equals("XX")){
    
    System.out.print("Code:" );
    
    code=in.next();
    
    if(code.equals("XX")){
    
    break;
    
    }
    
    System.out.print("Quantity: ");
    
    quantity=in.nextInt();
    
    
          }
     }
    }
    ================================================== ===================================

    NOW I WANT THESE TWO CLASS TO BE JOIN AND GIVE ONE OUTPUT IN MY THIRD CLASS
    Last edited by Norm; 02-16-2012 at 07:01 PM. Reason: added code tags

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    Please answer the questions I asked in post#10

    What is "ONE OUTPUT"?

  16. #16
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    i want the first class and the second to be in the third class to give an output!

    can i use instances?

  17. #17
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    Please post the program's current output and explain what parts of it you want moved to another class.

    If you want to control when and where a call to System.out.print() is made, put all the calls to it in a method.
    Then you can call that method from any other class.
    For example in pseudo code
    Java Code:
    class Aclass {
      public void printOutput() {
        System.out.print ...
        System.out.print...
        System.out.print ...
      }
    } // end Aclass
    
    class AnotherClass {
      Aclass ac = ??? get a reference some how.Pass it or create it with new
      public void someMethod() {
     
          ac.printOutput();  // call the method in Aclass to output stuff
       }
    }  // end class AnotherClass
    Last edited by Norm; 02-16-2012 at 07:10 PM.

  18. #18
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    can you give me an example how to call for something from another class please?

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,407
    Rep Power
    25

    Default Re: java assignment

    See my last post.

    Take a look at the tutorials:
    http://docs.oracle.com/javase/tutori...aOO/index.html
    Last edited by Norm; 02-16-2012 at 07:12 PM.

  20. #20
    Tuz
    Tuz is offline Member
    Join Date
    Feb 2012
    Posts
    17
    Rep Power
    0

    Default Re: java assignment

    System.out.print ... > WHAT SHOULD I WRITE?
    ???... > here i write the class i want to call?

Page 1 of 2 12 LastLast

Similar Threads

  1. java assignment
    By drewjordan in forum New To Java
    Replies: 9
    Last Post: 01-15-2012, 11:44 PM
  2. need help with a java assignment.
    By Z-slasher in forum New To Java
    Replies: 7
    Last Post: 04-17-2011, 11:05 PM
  3. Need Help with Java Assignment
    By smurf67 in forum New To Java
    Replies: 4
    Last Post: 03-26-2011, 10:25 AM
  4. Help me please (Java assignment)
    By cris_carriaga in forum Java Applets
    Replies: 4
    Last Post: 10-06-2010, 04:11 PM
  5. java assignment, need help bad.
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 11-06-2007, 04:53 PM

Posting Permissions

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