Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- //Class named CoffeeDriver
- public class CoffeeDriver {
- //Default main class
- public static void main(String[] args) {
- String ans;
- Scanner keyBoard = new Scanner(System.in); //Allows user input
- //Array to hold all of the items and prices
- item item[] = new item[5];
- item[0] =new item("Coffee", 1.00);
- item[0].setName("Coffee");
- item[0].setPrice(1.00);
- item[1] = new item("Water ", 2.00);
- item[1].setName("Water ");
- item[1].setPrice(2.00);
- item[2] =new item("Milk ", 1.50);
- item[2].setName("Milk ");
- item[2].setPrice(1.50);
- item[3] =new item("Bagel ", 1.25);
- item[3].setName("Bagel ");
- item[3].setPrice(2.00);
- item[4] = new item("Donut ", 0.75);
- item[4].setName("Donut ");
- item[4].setPrice(0.75);
- //Welcome message and directions
- System.out.println("Welcome to Peace's Coffee Shop! \n" );
- System.out.println ("Would you like to see these items sorted by "
- + "name or price? (n/p): ");
- ans = keyBoard.nextLine(); //Input from user on which sort to view
- System.out.println("Items:" + " " + "Price:");
- System.out.println(item[0].getName() + " " + item[0].getPrice());
- System.out.println(item[1].getName() + " " + item[1].getPrice());
- System.out.println(item[2].getName() + " " + item[2].getPrice());
- System.out.println(item[3].getName() + " " + item[3].getPrice());
- System.out.println(item[4].getName() + " " + item[4].getPrice());
- }
- public static void selectionSort2(int[] x) {
- for (int i=0; i<x.length-1; i++) {
- int minIndex = i; // Index of smallest remaining value.
- for (int j=i+1; j<x.length; j++) {
- if (x[minIndex] > x[j]) {
- minIndex = j; // Remember index of new minimum
- }
- }
- if (minIndex != i) {
- //... Exchange current element with smallest remaining.
- int temp = x[i];
- x[i] = x[minIndex];
- x[minIndex] = temp;
- }
- }
- }
- }
- //Class named Item
- public class item {
- private String name; //String instance to hold name
- private double price; //Double instance to hold price
- //Constructor to return values
- public item(String itemName, double itemPrice)
- {
- this.name = itemName;
- this.price = itemPrice;
- }
- //Get method for name
- public String getName()
- {
- return this.name;
- }
- //Set method for name
- public void setName(String Itemname)
- {
- this.name = Itemname;
- }
- //Get method for price
- public double getPrice()
- {
- return this.price;
- }
- //Set method for price
- public void setPrice(double Itemprice)
- {
- this.price = Itemprice;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement