Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAIN METODE::
- package Assignments;
- import java.util.Scanner;
- import org.omg.Messaging.SyncScopeHelper;
- public class WebShopping {
- public static void main(String[] args) {
- System.out.println("*********Welcome to the CBS webshop!*********");
- Scanner input = new Scanner(System.in);
- System.out.println("To create your profile, please fill out the"
- + " following personal information:");
- // First name
- System.out.println("First name: ");
- String firstname = input.nextLine();
- System.out.println(firstname + " is now registrated \n");
- //Last name
- System.out.println("Last name: ");
- String lastname = input.nextLine();
- System.out.println(lastname + " is now registrated \n");
- //Address
- System.out.println("Address: ");
- String address = input.nextLine();
- System.out.println(address + " is now registrated \n");
- //Postalcode
- System.out.println("Postalcode - it needs to be within the CPH area (1000-2500): ");
- int Postalcode = input.nextInt();
- while (Postalcode < 1000 || Postalcode > 2500) {
- System.out.println("Your Postalcode is not within the CPH area - try again");
- Postalcode = input.nextInt();
- }
- //CPR combined with Date of birth
- System.out.println(Postalcode + " is now registrated \n");
- System.out.println("Please insert your CPR in the following format ddmmyy-xxxx: ");
- String CPR = input.next();
- while (CPR.length() != 11 || CPR.charAt(6) != '-') {
- System.out.println("You have not entered your CPR in the right format - try again");
- CPR = input.next();
- }
- //Telephone
- System.out.println(CPR + " is now registrated \n");
- System.out.println("Please insert your eight digit telephonenumber: ");
- String Telephone = input.next();
- while (Telephone.length() != 8) {
- System.out.println("You have not entered your telephone number in the right format - try again");
- Telephone = input.next();
- }
- //Successful registration
- System.out.println(Telephone + " is now registrated \n" +
- "You have now succesfully registrated your personal informaton. You can find your log-in information beneath");
- //Username and password
- //Username:
- String s1 = firstname.substring(0,1);
- String s2 = lastname.substring(0,3);
- String username = s1 + s2;
- System.out.println("\nYour username has now been created. It is: " + username);
- //Password:
- String s3 = lastname.substring(0,3);
- String s4 = CPR.substring(7,CPR.length());
- String password = s3 + s4;
- System.out.println("Your password has now been created. It is: " + password);
- //Log-in or exit
- System.out.println("\nTo exit the program, please press 1: ");
- System.out.println("To login, please press 2: ");
- int exitorlogin = input.nextInt();
- while (exitorlogin > 3) {
- System.out.println("You haven't chosen one of above mentioned possibilities, try again");
- exitorlogin = input.nextInt(); }
- switch (exitorlogin) {
- case 1 :
- System.out.println("You have now exited the program, goodbye");
- break;
- case 2 :
- System.out.println("You can now log in. Please follow the next step");
- break;
- }
- //Type in username and password
- //username, three attempts:
- {
- System.out.println("\nEnter Username");
- String UsernameLogin = input.next();
- int count = 3;
- while (!UsernameLogin.equals(username)) {
- count--;
- System.out.println("Wrong Username, you have " + count + " attempts left");
- if (count==0) {
- System.out.print("Sorry you have exceeded the number of tries. Please try again after few hours");
- System.exit(0);
- }
- UsernameLogin = input.next();
- }
- }
- //password, three attempts:
- System.out.println(username + " is accepted");
- System.out.println("\nEnter Password");
- String PasswordLogin = input.next();
- int count = 3;
- while (!PasswordLogin.equals(password)) {
- count--;
- System.out.println("Wrong Password, you have " + count + " attempts left");
- if (count==0) {
- System.out.print("Sorry you have exceeded the number of tries. Please try again after few hours");
- System.exit(0);
- }
- PasswordLogin = input.next();
- }
- System.out.println("\nYou are now logged in!" );
- ProductDatabase pd = new ProductDatabase ();
- String mainMenu = ("Press 1 to browse boooks +\n"
- + " Press 2 to browse Sweatshirts\n"
- + " Press 3 to browse Caps");
- System.out.println(mainMenu);
- String chooseProducts = input.next();
- switch (chooseProducts) {
- case "1": pd.browseBooks(); break;
- case "2": pd.browseSwearshirts(); break;
- case "3": pd.browseCaps(); break;
- }
- }
- }
- ____________________________________________________________________________________________________________
- PRODUCT-DATABASE:
- package Assignments;
- import java.util.ArrayList;
- public class ProductDatabase {
- private ArrayList<Book> books = new ArrayList<Book>();
- private ArrayList<Cap> caps = new ArrayList<Cap>();
- private ArrayList<Swearshirt> sweatshirts = new ArrayList<Swearshirt>();
- ProductDatabase () {
- books.add(new Book(140, 1, "Lord of the rings", 11111111, "Jjr tolkien", 500));
- books.add(new Book(100, 2, "Harry Potter", 1234567, "Rowlings", 600));
- System.out.println("/n");
- sweatshirts.add(new Swearshirt(100, 1, "Black", "Medium"));
- sweatshirts.add(new Swearshirt(100, 2, "Yellow", "Medium"));
- sweatshirts.add(new Swearshirt(100, 3, "Red", "Small"));
- sweatshirts.add(new Swearshirt(100, 4,"Green", "Medium"));
- System.out.println("\n Caps 1: ");
- caps.add(new Cap(100, 1, "Medium fit", "Medium", "Black", true));
- caps.add(new Cap(50, 2, "Medium fit", "Medium", "Black", false));
- caps.add(new Cap(100, 3, "Medium fit", "Medium", "Black", true));
- caps.add(new Cap(75, 4, "Medium fit", "Medium", "Black", true));
- }
- public void addBook() {
- }
- public void addSweatshirt(Swearshirt sweatshirt) {
- sweatshirts.add(sweatshirt);
- }
- public void addCap(Cap cap) {
- caps.add(cap);
- }
- public void browseBooks() {
- if (!books.isEmpty())
- {
- for (Book b : books)
- {
- System.out.println("\n Available books: ");
- System.out.println("Title: " + b.getTitle());
- System.out.println("Price: " + b.getPrice());
- System.out.println("Id: " + b.getId());
- System.out.println("ISBN: " + b.getISBN());
- System.out.println("Author: " + b.getAuthor());
- System.out.println("Number of pages: " + b.getPage());
- }
- }
- else System.out.println("Sorry, no books available");
- }
- public void browseSwearshirts(){
- if (!sweatshirts.isEmpty())
- {
- for (Swearshirt s : sweatshirts)
- {
- System.out.println("\n");
- System.out.println("Price: " + s.getPrice());
- System.out.println("Id: " + s.getId());
- System.out.println("Colour: " + s.getcolour());
- System.out.println("Size: " + s.getsize());
- }
- }
- else System.out.println("Sorry, no sweatshirts available");
- }
- public void browseCaps(){
- if (!caps.isEmpty())
- {
- for (Cap c : caps)
- {
- System.out.println("\n");
- System.out.println("Price: " + c.getPrice());
- System.out.println("Id: " + c.getId());
- System.out.println("Colour: " + c.getColour());
- System.out.println("Size: " + c.getSize());
- System.out.println("Fit: " + c.getFit());
- System.out.println("Embroidery: " + c.getEmbroidery());
- }
- }
- else System.out.println("Sorry, no caps available");
- }
- }
- ____________________________________________________________________________________________________________
- CAP::
- package Assignments;
- public class Cap extends Product{
- private String fit, size, colour;
- private boolean embroidery;
- public Cap (double price, int id, String fit, String size, String colour, boolean embroidery ) {
- this.fit = fit;
- this.size = size;
- this.colour = colour;
- this.embroidery = embroidery;
- }
- public String getFit() {
- return fit;
- }
- public void setFit(String fit) {
- this.fit = fit;
- }
- public String getSize() {
- return size;
- }
- public void setSize(String size) {
- this.size = size;
- }
- public String getColour() {
- return colour;
- }
- public void setColour(String colour) {
- this.colour = colour;
- }
- public boolean getEmbroidery() {
- return embroidery;
- }
- public void setEmbroidery(boolean embroidery) {
- this.embroidery = embroidery;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement