Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 personStack = new Stack<>();// JDK stack has no limits

//!!! 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 intQueue1 = new LinkedList<>();

PriorityQueue intQueue2 = new 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 it = intQueue1.iterator(); while(it.hasNext()){ int x = it.next(); if(x

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

Students also viewed these Databases questions

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago