Results 1 to 6 of 6
  1. #1
    nura23 is offline Member
    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0

    Post Require HELP, Please

    //////////////////////////////////////////Computer.java
    Java Code:
    package customer;
    import java.util.*;
    
    abstract class Computer {
        public String make;
        public String cpuType;
        public double cpuSpeed;
        public int ramMemory;
        public String graphicCard;
        public int hardDrive;
        public int monitorSize;
        public double price;
    
     public void createComputer(){
    //  MAKE
            Scanner input = new Scanner (System.in);
            System.out.println("Please enter the Make of the Desktop. Eg: DELL, Samsung, Sony");
            System.out.print("Your Input: ");
            String mk = input.next();
            this.make = mk;
         }
        
        public void DisplayC(){
            System.out.println("Make            : "+make);
        }
    }
    ///////////////////////////////////////////////////////////// Desktop.java
    Java Code:
    package customer;
    import java.util.*;
    
    class Desktop extends Computer{
        public String mouse;
        public String keyboard;
    public void intputOpt1(){
            System.out.println("You want to create a Desktop.");
            Computer d1 = new Desktop();//
            d1.createComputer();
        }
    
        public void selectMouse(){
            System.out.println("Please select one option.");
            System.out.println("__________________________");
            System.out.println("'1':    wireless Mouse.");
            System.out.println("'2':    without wireless Mouse.");
            System.out.println("__________________________");
            System.out.print("Your Input: ");
            Scanner input= new Scanner(System.in);
            mouse= input.next();
            char m = mouse.charAt(0);
            while(m != '1'  && m != '2'){
                System.out.println("ERROR: Incorrect input. Please Try Again");
                mouse= input.next();
                m = mouse.charAt(0);
            }
            if(m == '1'){
                mouse= "Wireless Mouse";
            }
            else{
                mouse= "Without wireless Mouse";
            }
            System.out.println();
        }
    
    
        public void selectKeyboard(){
            System.out.println("Please select one option.");
            System.out.println("__________________________");
            System.out.println("'1':    wireless Keyboard.");
            System.out.println("'2':    without wireless Keyboard.");
            System.out.println("__________________________");
            System.out.print("Your Input: ");
            Scanner input= new Scanner(System.in);
            keyboard= input.next();
            char m = keyboard.charAt(0);
            while(m != '1'  && m != '2'){
                System.out.println("ERROR: Incorrect input. Please Try Again");
                keyboard= input.next();
                m = keyboard.charAt(0);
            }
            if(m == '1'){
                keyboard= "Wireless Keyboard";
            }
            else{
                keyboard= "Without wireless Keyboard";
            }
            System.out.println();
        }
    
        public void DisplayD(){
            System.out.println("Mouse Type      : "+mouse);
            System.out.println("Keyboard Type   : "+keyboard);
            this.DisplayC();
        }
    }
    //////////////////////////////////////// Menu.java
    Java Code:
    package customer;
    import java.util.*;
    
    public class Menu {
         public static void main(String[] args) {
                Desktop d1=new Desktop();                              
                d1.selectKeyboard();
                d1.selectMouse();
    //  then it access the computer option which is make
                d1.intputOpt1();
    //  Displays what options have been selected for the desktop.
                d1.DisplayD();
    }
    ////////////////////// 3 Java Files ///////////////////////
    It displayes the keyboard and the mouse. the only one that is showing 'null' is the make which is in the Computer.java.

    Any solution will be helpful. Thank you in advance.
    Last edited by Fubarable; 01-09-2010 at 01:32 AM. Reason: Code tags added

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by nura23 View Post
    Any solution will be helpful. Thank you in advance.
    I guess so but what is your question?

    kind regards,

    Jos

  3. #3
    nura23 is offline Member
    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0

    Default

    The 'make' in computer.java
    when i type 'Dell' itis stored in the make variable but when i try to display the content of make variable, it displays 'null' on the screen.
    This is my problem, I don't know why it displays a null value for variable make.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    One of your problems as I see it is that you are dealing with more than one Computer object, and the one that has its variable "make" set is not the same as the one that you try to have display the "make" String.

    Here is where you set make by calling createComputer():
    Java Code:
        public void intputOpt1() {
            System.out.println("You want to create a Desktop.");
            Computer d1 = new Desktop();//
            d1.createComputer();
        }
    You create a Computer object here, d1, set it's make by callilng d1.createComputer(), but once this method ends, d1 goes out of scope and along with it, the make String that it contains.

    your other computer object is the Desktop object itself (this) here:
    Java Code:
    class Desktop extends Computer {
    and it is this object that you call DisplayC on here:
    Java Code:
        public void DisplayD(){
            System.out.println("Mouse Type      : "+mouse);
            System.out.println("Keyboard Type   : "+keyboard);
            this.DisplayC();
        }
    Solution, don't create a new Computer object, d1, but instead call createComputer on "this" just like you are calling DisplayC on "this".

    Also: please learn Java naming conventions as your non-standard naming makes your code hard to read and hard to fix.

    Also: please use code tags here (see my signature below) as it makes your posted code easier to read. I've added them to your first post.

    Good luck!
    Last edited by Fubarable; 01-09-2010 at 02:21 AM.

  5. #5
    nura23 is offline Member
    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0

    Talking Thanx

    Thank you very much!!;-)
    This problem is solved.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. I require some urgent help... plzzzz help me
    By Hurricane in forum New To Java
    Replies: 3
    Last Post: 08-29-2009, 06:49 PM
  2. Require SCJP 1.6 exam ticket
    By nphariharan in forum Java Certification
    Replies: 0
    Last Post: 07-12-2009, 07:06 PM
  3. Help require to capture streaming data
    By jobseeker in forum Java Servlet
    Replies: 1
    Last Post: 04-02-2009, 09:18 PM
  4. Require Help with Layout (GridBag)
    By hemanthjava in forum AWT / Swing
    Replies: 2
    Last Post: 10-22-2008, 01:56 PM
  5. Require some insight!
    By Shaolin in forum JavaServer Pages (JSP) and JSTL
    Replies: 13
    Last Post: 07-15-2008, 11:36 PM

Tags for this Thread

Posting Permissions

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