Ok so this is my code so far: I have a issue where near the end in the getSum() method I need a way for the all the methods that i have that ask for the user input need to go into the respective arrays that i made in the getSum method then the prices i assigned in my Constructor to be linked to each selection the user made for that particular component for their computer and then display the "reciept" in the DisplayResults method...racking my brain trying to figure that out...

Thanks guys

public class Computer 
{
     //memory locations 
    //initialized to zero before setting prices 
    private double processorSpeed = 0; 
    private double memory = 0; 
    private double diskSize = 0; 
    private double screenSize = 0;
    private String inputResponse;



    //default constructor 
    public Computer() 
    {

    }

    //assigns prices
    public Computer(double processorSpeed , double memory , double diskSize , double screenSize)
    {
        //prices for computer parts
        //goes up by each next higher model 
        //i.e Intel i3 $40 so next higher will be $80 , same for Ram 
        processorSpeed = 40; 
        memory = 10; 
        diskSize = 20; 
        screenSize = 10;

    } // end of Computer constructor for prices 

    //userPrompt 

    static Scanner userInput = new Scanner(System.in);

    public static void DisplayInstructions()
    {
    /// User Prompt 
    System.out.println("Hi Welcome to Sam and Johnny's PC Shop! Please type enter to continue..." );
    //initialize Scanner variable and set it too null
    //take user input to proceed to next Screen

    String pressAnyKey; 

    pressAnyKey = userInput.next();

    }

    public static void notebookOrDesktop(){
        System.out.print("What would you like to purchase today? ");
        System.out.println("\n\n1.PC\n2.Laptop"); 
        System.out.println("\nPlease type number for selection");

        String selectOptionSystem; 


        do {
            selectOptionSystem= userInput.next();
            if (selectOptionSystem.equalsIgnoreCase("1")) 
                  {

                 }else{
                     screenSize();

                 }
        }   while (false);


    }

    public static void processor(){
        System.out.print("What processor would you like to have? ");
        System.out.println("\n\n1. Intel i7 \n2. Intel i5 \n3. Intel i3"); 
        System.out.println("\nPlease type number for selection");

        String selectOption; 

        selectOption = userInput.next();
    }

    public static void ram(){
        System.out.print("How much RAM would you like to have? ");
        System.out.println("\n\n1. 2gb \n2. 4gb \n3. 8gb"); 
        System.out.println("\nPlease type number for selection");

        String selectOption; 

        selectOption = userInput.next();
    }

    public static void diskSize(){
        System.out.print("How much disk space do you need? ");
        System.out.println("\n\n1. 200gb \n2. 400gb \n3. 1 tb"); 
        System.out.println("\nPlease type number for selection");

        String selectOption; 

        selectOption = userInput.next();
    }

    public static void screenSize(){

        System.out.print("\nPlease Choose Your Screen Size ");

        System.out.println("\n\n1.13in \n2. 15in \n3. 17in"); 
        System.out.println("\nPlease type number for selection");

        String selectOption; 

        selectOption = userInput.next();
    }

    public static void DriveOption() 
    {
        System.out.println("Would you like to add a CD Drive or DVD Drive? Enter Y or N "); 

        String selectOption; 
        selectOption = userInput.next(); 

        do {
            selectOption= userInput.next();
            if (selectOption.equalsIgnoreCase("N")) 
                  {
                      //have it total and displayResults(); 
                     DisplayResults();
                 }else{
                       DriveOption();
                 }
        }   while (false);
    } 

    public static void DisplayResults() 
    {
        System.out.println("Your order and total:");







    } // end of DisplayResults

    public static void getSum()
    {
        //need to have what ever component user selected and store that part with the price into array and loop and total all the parts and 
        //list them with their prices 
           int [] processor = new int [] { };
           int [] ram = new int [] {};
           int [] HDD = new HDD [] {}; 
           int [] disk = new disk[] {}; 



              int sum = 0;
              for (int i = 0; i < userSelection.length; i++)
                    {
                        sum += userSelection[i];
                    }
                    return sum;



    } // end of getSum method 


    //start main method 
    public static void main(String[] args)
    {
        //declare array
        int [] userSelection; 
        //initialize array 
        userSelection = new int[4];


        DisplayInstructions();

        notebookOrDesktop();
        processor();
        ram();
        diskSize();
        DriveOption();
        DisplayResults();


        //Processor



    } // end of main 






} // end of computer class

Recommended Answers

All 3 Replies

a way for the all the methods that i have that ask for the user input need to go into the respective arrays

Use a loop for each array that asks for the user's input, reads the input and stores it into the array.

Is there any correspondence between the items in each array? Having data in separate arrays will make for problems. Better to define a class to hold all the data for one item, get all the data needed to create an instance of the class, create the instance and store it in an arraylist.

yea all the items in the array are the "parts" for a desktop or notebook the user is putting together. I guess i could define two arrays one in a class called "Notebook" and the other "Desktop" and accept the user input in those classes and then finally have it output to the DisplayInstructions

Putting all the data in a class vs in a bunch of arrays will make the code easier to work with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.