. /Math.java:1: error: class MathUtils is public, should be declared in a file named Mathutils.jav public class MathUtils BankServise.java:153: error: cannot access Math int newCustomers = (int) (Math.random() * 10) + 1; bad source file: ./Math.java file does not contain class Math Please remove or make sure it appears in the correct subdirectory of the sourcepath. 2 errors

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

How to fix the error?

import java.util.*;

import java.util.Iterator;
import java.util.NoSuchElementException;

class LinkedQueue<Item> implements Iterable<Item> {
    private int n;         
    private Node first;    
    private Node last;     

    private class Node {
        private Item item;
        private Node next;
    }

    public LinkedQueue() {
        first = null;
        last  = null;
        n = 0;
        assert check();
    }

    public boolean isEmpty() {
        return first == null;
    }


    public int size() {
        return n;     
    }

    public Item peek() {
        if (isEmpty()) throw new NoSuchElementException("Queue underflow");
        return first.item;
    }

    public void enqueue(Item item) {
        Node oldlast = last;
        last = new Node();
        last.item = item;
        last.next = null;
        if (isEmpty()) first = last;
        else           oldlast.next = last;
        n++;
        assert check();
    }

    public Item dequeue() {
        if (isEmpty()) throw new NoSuchElementException("Queue underflow");
        Item item = first.item;
        first = first.next;
        n--;
        if (isEmpty()) last = null;   
        assert check();
        return item;
    }

    public String toString() {
        StringBuilder s = new StringBuilder();
        for (Item item : this)
            s.append(item + " ");
        return s.toString();
    } 

    private boolean check() {
        if (n < 0) {
            return false;
        }
        else if (n == 0) {
            if (first != null) return false;
            if (last  != null) return false;
        }
        else if (n == 1) {
            if (first == null || last == null) return false;
            if (first != last)                 return false;
            if (first.next != null)            return false;
        }
        else {
            if (first == null || last == null) return false;
            if (first == last)      return false;
            if (first.next == null) return false;
            if (last.next  != null) return false;

            int numberOfNodes = 0;
            for (Node x = first; x != null && numberOfNodes <= n; x = x.next) {
                numberOfNodes++;
            }
            if (numberOfNodes != n) return false;

            Node lastNode = first;
            while (lastNode.next != null) {
                lastNode = lastNode.next;
            }
            if (last != lastNode) return false;
        }

        return true;
    } 
 
    public Iterator<Item> iterator()  {
        return new LinkedIterator();  
    }

    private class LinkedIterator implements Iterator<Item> {
        private Node current = first;

        public boolean hasNext()  { return current != null;                     }
        public void remove()      { throw new UnsupportedOperationException();  }

        public Item next() {
            if (!hasNext()) throw new NoSuchElementException();
            Item item = current.item;
            current = current.next; 
            return item;
        }
    }
}

class Customer {

              private static int custId = 0;

              private String name;

              public Customer() {

                           name = "Customer " + custId;

                           custId++;
              }

              public String getName() {

                           return name;
              }

              public String toString() {

                           return name;
              }

}

public class BankServise{
              public static void main(String[] args) {

                           LinkedQueue<Customer> customerQueue = new LinkedQueue<Customer>();

                           int counter = 0;

                           while (counter < 10) {

                                         int newCustomers = (int) (Math.random() * 10) + 1;

                                         for (int i = 0; i < newCustomers; i++) {

                                                       Customer c = new Customer();

                                                       customerQueue.enqueue(c);

                                                       System.out.println(c + " is waiting in line");
                                         }

                                         int servingCustomers = (int) (Math.random() * 10) + 1;

                                         for (int i = 0; i < servingCustomers; i++) {

                                                       if (customerQueue.isEmpty()) {

                                                                    break;
                                                       }

                                                       System.out.println(customerQueue.dequeue() + " at the teller window");
                                         }

                                         counter++;

                           }

                           while (!customerQueue.isEmpty()) {

                                         System.out.println(customerQueue.dequeue() + " is being served");
                           }
              }
}

 

. /Math.java:1: error: class MathUtils is public, should be declared in a file named Mathutils.java
public class Mathutils
BankServise.java:153: error: cannot access Math
int newCustomers = (int) (Math.random() * 10) + 1;
bad source file: ./Math.java
file does not contain class Math
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
2 errors
Transcribed Image Text:. /Math.java:1: error: class MathUtils is public, should be declared in a file named Mathutils.java public class Mathutils BankServise.java:153: error: cannot access Math int newCustomers = (int) (Math.random() * 10) + 1; bad source file: ./Math.java file does not contain class Math Please remove or make sure it appears in the correct subdirectory of the sourcepath. 2 errors
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education