Question
JAVA- I can't get this code to compile. This is the error I am getting: run: Exception in thread main java.lang.RuntimeException: Uncompilable source code -
JAVA- I can't get this code to compile. This is the error I am getting:
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: class Stack
location: class Lab7
at Lab7.testStack(Lab7.java:16)
at Lab7.main(Lab7.java:7)
//////////////////////////////////////////////////
class Lab7
{
public static void main(String[] args) {
testStack();
testQueue();
}
private static void testStack() {
Stack
//!!! add five persons with different names and ages
personStack.push(new Person("Donald", "Trump", 70)); personStack.push(new Person("Hillary", "Clinton", 66)); personStack.push(new Person("James", "emerald", 23)); personStack.push(new Person("kete", "Williams", 40)); personStack.push(new Person("Kit", "willington", 33));
//!!! print contents of the stack
for (Person p : personStack) { System.out.println(p); }
//!!! find a person with smallest age and prints the person
Person smallestAge = personStack.get(0); for (Person p : personStack) { if (p.getAge() < smallestAge.getAge()) { smallestAge = p; } } System.out.println("Person with smallest age : " + smallestAge);
}
private static void testQueue() {
Queue
PriorityQueue
//!!! Add 10 random numbers (0 ~ 99) to queue and priority queue
Random r = new Random(); for (int i = 0; i < 10; i++) { intQueue1.add(r.nextInt(100)); }
//!!! Each queue should have different random numbers
//!!! Use offer for queues
for (int i = 0; i < 10; i++) { intQueue2.offer(r.nextInt(100)); }
//!!! Find the smallest number from all. int MIN = intQueue1.peek();
//!!! Use an iterator for intQueue1.
Iterator for(int x : intQueue2){ if(x System.out.println("Minimum element : "+MIN); //!!! Remove all elements from both queues System.out.println("Removing elements from Queue1"); while(!intQueue1.isEmpty()){ intQueue1.remove(); System.out.println(intQueue1); } System.out.println("Removing elements from Queue2"); while(!intQueue2.isEmpty()){ intQueue2.remove(); System.out.println(intQueue2); } //!!! For each element removed, print content of the queues //!!! Use remove for queue } } import java.util.*; class Person { private String lastName; private String firstName; private int age; public Person(String first, String last, int age) { lastName = last; firstName = first; this.age = age; } @Override public String toString() { String result = ""; //!!! return "person info: firstName lastName, age" return "Person : " + firstName + " " + lastName + ", " + age; } public int getAge() { return age; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started