Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Furniture
- {
- public static void main(String[] args)
- {
- Scanner scan = new Scanner(System.in);
- int count = 0;
- char input = ']';
- String[] nameArray = new String[1];
- double[] costArray = new double[1];
- do
- {
- System.out.print("What action would you like to perform?\n\n");
- printMenu();
- input = scan.next().charAt(0);
- String uppercase = Character.toString(input);
- uppercase = uppercase.toUpperCase();
- input = uppercase.charAt(0);
- String furnitureName;
- if (input == 'A' || input == 'S' || input == 'L' || input == 'C' || input == 'T' || input == 'R' || input == 'Q' || input == '?')
- {
- switch(input)
- {
- case 'A':
- do
- {
- System.out.print("Please enter a furniture to add:\n");
- furnitureName = scan.next();
- nameArray[count] = furnitureName.substring(0, 1).toUpperCase() + furnitureName.substring(1);
- if(!furnitureName.equalsIgnoreCase("done"))
- {
- System.out.print("Please enter a price for the " + furnitureName + ":\n");
- double furniturePrice = scan.nextDouble();
- costArray[count] = furniturePrice;
- count++;
- String[] nameArray2 = new String[count + 1];
- double[] costArray2 = new double[count + 1];
- for(int i = 0; i < count; i++)
- {
- nameArray2[i] = nameArray[i];
- costArray2[i] = costArray[i];
- }
- nameArray = nameArray2;
- costArray = costArray2;
- }
- }
- while(!furnitureName.equalsIgnoreCase("done"));
- break;
- case 'S':
- System.out.print("Please enter a furniture name to search for:\n");
- String searchedFurniture = scan.next();
- boolean found = false;
- for(int i = 0; i < count; i++)
- {
- if(nameArray[i].equalsIgnoreCase(searchedFurniture))
- {
- System.out.print("Furniture Name: " + nameArray[i] + " | Cost: $" + costArray[i]);
- found = true;
- }
- if(found = false)
- {
- System.out.print("No furniture by the name '" + searchedFurniture + "' was found.\n");
- }
- }
- break;
- case 'L':
- System.out.println("\n");
- System.out.println("Furniture List:\n----------------------------------------\n");
- for(int i = 0; i < count; i++)
- {
- System.out.print("Furniture Name: " + nameArray[i] + "\t\t| Cost: " + costArray[i] + "\n");
- }
- System.out.println();
- break;
- case 'C':
- int finalCount = count;
- System.out.println("There are currently " + finalCount + " furniture in the list.");
- System.out.println();
- break;
- case 'T':
- double price = 0;
- for(int i = 0; i < count; i++)
- {
- price += costArray[i];
- }
- System.out.println("Total Cost: $" + price);
- break;
- case 'R':
- System.out.print("Please enter the name of a furniture you would like to remove:\n");
- String removedFurniture = scan.next();
- int counting = count - 1;
- boolean find = false;
- boolean furniFound = false;
- String[] nameArray3 = new String[counting];
- double[] costArray3 = new double[counting];
- int c = 0;
- while(furniFound == false)
- {
- if(nameArray[c].equalsIgnoreCase(removedFurniture))
- {
- find = true;
- furniFound = true;
- }
- else
- {
- find = false;
- }
- c++;
- }
- if(find == false)
- {
- System.out.print("No furniture with that name was found.\n");
- }
- if(find == true)
- {
- int counter = 0;
- for(int i = 0; i < count; i++)
- {
- if(nameArray[i].equalsIgnoreCase(removedFurniture))
- {
- counter--;
- }
- else
- {
- nameArray3[counter] = nameArray[i];
- costArray3[counter] = costArray[i];
- counter++;
- }
- }
- nameArray = nameArray3;
- costArray = costArray3;
- System.out.print("Furniture removed.\n");
- }
- break;
- case 'Q':
- break;
- case '?':
- printMenu();
- break;
- }
- }
- }
- while(input != 'Q');
- }
- public static void printMenu()
- {
- System.out.print("Choice\t\tAction\n" +
- "------\t\t------\n" +
- "A\t\tAdd Furniture\n" +
- "S\t\tSearch for Furniture\n" +
- "L\t\tList Current Furniture\n" +
- "C\t\tCount Furniture\n" +
- "T\t\tTotal Cost\n" +
- "R\t\tRemove Furniture\n" +
- "Q\t\tQuit\n" +
- "?\t\tDisplay Help\n\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement