Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- public class GameStore3 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int ids[] = new int[100];
- double sum = 0;
- int nm = 0;
- int index = 0;
- while (true) {
- System.out.print("**********************************************************************"
- + "\n* Welcome to Gaming Center :) *"
- + "\n* -------------------------- *"
- + "\n* Please enter one of the following options: *"
- + "\n* 1) add ==> this allows you to add a game to inventory *"
- + "\n* 2) sell ==> this allows you to sell games to a customer *"
- + "\n* 3) exit ==> to end this program *"
- + "\n* *"
- + "\n**********************************************************************\n");
- System.out.print("Enter your option :> ");
- String choice = input.nextLine();
- if (choice.equals("add")) {
- while (true) {
- System.out.print("Please, enter game id (-1 to end): ");
- int id = input.nextInt();
- if (id == -1) {
- break;
- } else {
- ids[(index++)] = id;
- }
- }
- } else if (choice.equals("sell")) {
- if (index <= 0) {
- System.out.print("Sorry. There are no more games in store :(\n");
- }
- else {
- while (true) {
- System.out.print("Please, enter the game id (-1 to end): ");
- int id = input.nextInt();
- if (id == -1) {
- break;
- } else {
- boolean exists = false;
- for (int i = 0; i < ids.length; i++) {
- if (ids[i] == id)
- exists = true;
- ids[i] = 0;
- }
- if (exists) {
- System.out.print("Please, enter the price of next game: \n");
- sum += input.nextDouble();
- nm += 1;
- } else {
- System.out.print("Sorry the id you inserted doesnt exist\n");
- }
- }
- }
- System.out.print("Total price before discount: " + sum + "SR" + "\nYour discount is: "
- + ((nm <= 2) ? "0.0SR" : sum * 0.2 + "SR") + "\nTotal price after discount: "
- + ((nm <= 2) ? sum : sum * 0.8 + "SR\n"));
- }
- } else if (choice.equals("exit")) {
- System.out.print("Thanks. Goodbye!");
- break;
- } else {
- System.out.print(choice == "add");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement