Results 1 to 8 of 8
  1. #1
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default Online Computer Shop Java (Please Help)

    Hey guys I am still learning how to use simple java. I want to try to do this program which i found in some book, but i cant seem to get how to started. They say its a beginners program, but i found it quite difficult on how to start.

    can someone please give me some way to start the code, so i can at least look and learn.

    thanks

    Here are the instructions for this java program:

    Create a pricing system for a company that makes individualized computers, such as you might see on a Website. There are two kinds of computers: notebooks and desktop computers. The customer can select the processor speed, the amount of memory, and the size of the disk drive. The customer can also choose either a CD drive (Cd rom, cd-rw), a DVD drive, or both. For notebooks, there is a choice of screen size. Other options are a modem, a network card, or a wireless network. You should have a abstract class Computer and subclasses Desktop and Notebook. Each subclass should have methods for calculating the price of a computer, given the base price plus the cost of the different options. You should have methods for calculating memory price, hard drive price, and so on. There should be a method to calculate shipping cost.


    Thanks


    UPDATE:
    Here is the most i Could get for this program. I am missing main class and having trouble with rest

    Computer.java

    Java Code:
    
    public class Computer {
    
    private String manufacturer;
    private String processor;
    private double ramSize;
    private int diskSize;
    private double processorSpeed;
    
    
        public Computer(String man, String processor, double ram, int disk, double procSpeed){
            manufacturer = man;
            this.processor = processor;
            ramSize = ram;
            diskSize = disk;
            processorSpeed = procSpeed;
        }
    
    
        public double computePower(){
            return ramSize * processorSpeed;
        }
        public double getRamSize(){
            return ramSize;
        }
        public double getprocessorSpeed(){
            return processorSpeed;
        }
        public int getDiskSize(){
            return diskSize;
        }
       
        @Override
        public String toString(){
            String result = "Manufacturer: " +manufacturer+
                          "\nCPU: " +processor+
                          "\nRam: " +ramSize+ "megabytes" +
                          "\nDisk: " +diskSize+ "gigabytes" +
                          "\nProcessor speed: " +processorSpeed+ "gigahertz";
            return result;
        }
    
    }
    Notebook.java
    Java Code:
    
    public class Notebook extends Computer {
        private static final String DEFAULT_NB_MAN = "MyBrand";
        private double screenSize;
        private double weight;
       
    
        public Notebook (String man, String proc,int ram, int disk, double procSpeed, double screen, double wei){
     
            super(man, proc, ram, disk, procSpeed);
            screenSize = screen;
            weight = wei;
           
        }
         
        public Notebook( String proc, int ram, int disk, double procSpeed, double screen, double wei ){
            this(DEFAULT_NB_MAN, proc, ram, disk, procSpeed, screen, wei);
           
           
        }
       
        @Override
        public String toString() {
            String result = super.toString() +
                                "\nScreen size: " +screenSize+ "inches" +
                                "\nWeight: " +weight + "pounds";
            return result;
        }
        }
    Desktop.java
    Java Code:
    
    
    public class Desktop extends Computer{
       
        private int basePrice = 500;
       
        private int totalPrice = 0;
    
        public void addComponent(int price, int amount){
            totalPrice += price*amount;   
        }
       
        public void addMemory(int amount){
            addComponent(Prices.MEMORY_1GB,amount);
        }
       
       
        public int getPrice() {
            return basePrice + totalPrice;
        }
    
        public static class Prices{
            public static int MEMORY_1GB = -1;
            public static int DISK_1GB = -1;
            public static int PROCESSOR_2GHZ = -1;
            public static int PROCESSOR_4GHZ = -1;
        }
    }
    Thanks,

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What kind of troubles are you running into? It seems like you have the classes created correctly, now you have to use a scanner in a main method to allow users to make choices, you can also set up menus with switch cases and such in main. Set up a main function and play around with choice selections and make tweaks where necessary.

  3. #3
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    Can you please help me with main method.
    What do you think is best to put there.

    Thanks

  4. #4
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default

    I imagine the main would be used to prompt a user to choose which computer and options they want. Then create a Computer object and get it to display the cost.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The main method is essentially the program. You can for instance print out
    Java Code:
    What would you like to purchase?
    1. something
    2. something else
    3. something else
    Then they can make a choice by typing in a number and pressing enter, and then you can create a switch statement to do the appropriate action for a choice, From this information you gather you can then create a computer object.

    You will need to read about the following:
    The switch Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Scanner (Java Platform SE 6)

    Be creative with what you allow in the main method, then continually run the program testing all possible choices and make sure everything works how you wanted, you can find a lot of problems by playing around with main and running it. Just remember, designing the class itself was probably the hardest part of this problem.

    Also, the problem asks for an abstract computer class, an abstract class cannot be created, read about abstract classes:
    http://download.oracle.com/javase/tu.../abstract.html

    There are some improvements you can make in the classes besides that but try and fix the abstract situation first, then work on getting a main method built to play around with it.
    Last edited by sunde887; 01-28-2011 at 12:07 AM.

  6. #6
    acash229 is offline Member
    Join Date
    Sep 2010
    Posts
    60
    Rep Power
    0

    Default

    Hey Okay I have tried to mess with it and got this:

    This is what i get for my output:
    price of notebook: Manufacturer: man
    CPU: proc
    Ram: 0.0megabytes
    Disk: 0gigabytes
    Processor speed: 0.0gigahertz
    Screen size: 0.0inches
    Weight: 0.0pounds
    price of desktop : 900


    *What i want is for my program to ask user what he wants.

    Can someone please help me finish this up.

    Thanks:


    Computer.java
    Java Code:
    package javaapplication13;
    
    
    public class Computer {
    
    private String manufacturer;
    private String processor;
    private double ramSize;
    private int diskSize;
    private double processorSpeed;
    
    
       
    public static void main(String[] args) {
            // entry point
              Notebook notebook = new Notebook("man", "proc",0, 0, 0, 0, 0); // give your own arguments
              Desktop desktop   = new Desktop("", "", 0, 0, 0);
    
              desktop.addComponent(200, 2);
    
              System.out.println("price of notebook: "+ notebook.toString());
              System.out.println("price of desktop  : " + desktop.getPrice());
            }
    
        public Computer(String man, String processor, double ram, int disk, double procSpeed){
            manufacturer = man;
            this.processor = processor;
            ramSize = ram;
            diskSize = disk;
            processorSpeed = procSpeed;
        }
    
    
        public double computePower(){
            return ramSize * processorSpeed;
        }
        public double getRamSize(){
            return ramSize;
        }
        public double getprocessorSpeed(){
            return processorSpeed;
        }
        public int getDiskSize(){
            return diskSize;
        }
    
        @Override
        public String toString(){
            String result = "Manufacturer: " +manufacturer+
                          "\nCPU: " +processor+
                          "\nRam: " +ramSize+ "megabytes" +
                          "\nDisk: " +diskSize+ "gigabytes" +
                          "\nProcessor speed: " +processorSpeed+ "gigahertz";
            return result;
        }
    
    }

    Desktop.java
    Java Code:
    package javaapplication13;
    
    
    
    public class Desktop extends Computer{
    
        private int basePrice = 500;
    
        private int totalPrice = 0;
    
    
        public Desktop(String man, String processor, double ram, int disk,
             double procSpeed) {
          super(man, processor, ram, disk, procSpeed);
          // TODO
       }
    
        public void addComponent(int price, int amount){
            totalPrice += price*amount;
        }
    
        public void addMemory(int amount){
            addComponent(Prices.MEMORY_1GB,amount);
        }
    
    
        public int getPrice() {
            return basePrice + totalPrice;
        }
    
        public static class Prices{
            public static int MEMORY_1GB = -1;
            public static int DISK_1GB = -1;
            public static int PROCESSOR_2GHZ = -1;
            public static int PROCESSOR_4GHZ = -1;
        }
    }
    Notebook.java
    Java Code:
    package javaapplication13;
    
    
    public class Notebook extends Computer {
        private static final String DEFAULT_NB_MAN = "MyBrand";
        private double screenSize;
        private double weight;
    
    
        public Notebook (String man, String proc,int ram, int disk, double procSpeed, double screen, double wei){
    
            super(man, proc, ram, disk, procSpeed);
            screenSize = screen;
            weight = wei;
    
        }
    
        public Notebook( String proc, int ram, int disk, double procSpeed, double screen, double wei ){
            this(DEFAULT_NB_MAN, proc, ram, disk, procSpeed, screen, wei);
    
    
        }
    
        @Override
        public String toString() {
            String result = super.toString() +
                                "\nScreen size: " +screenSize+ "inches" +
                                "\nWeight: " +weight + "pounds";
            return result;
        }
        }

  7. #7
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default

    Have you covered getting user input? I imagine you have otherwise this assingment would not have been set. So read your text book and/or lecture notes. In particular you want to read about BufferedReader or Scanner.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Ask them for the correct info, store the info in variables, and then create a computer object with those parameters and it should work pretty well, You can get creative with how the selections and such work.

Similar Threads

  1. Java Computer Shop Help (Please)
    By acash229 in forum New To Java
    Replies: 2
    Last Post: 01-27-2011, 08:39 PM
  2. Replies: 0
    Last Post: 03-06-2010, 06:15 PM
  3. Computer Shop - New Version
    By mindblaster in forum New To Java
    Replies: 6
    Last Post: 02-10-2010, 12:00 PM
  4. Help needed with 'shop' program
    By jkhamler in forum New To Java
    Replies: 1
    Last Post: 12-06-2009, 05:35 PM
  5. E-shop with error
    By snowbirdie in forum Advanced Java
    Replies: 1
    Last Post: 05-04-2008, 05:35 AM

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
  •