import java.util.NoSuchElementException;
public class LinkedStringList {
private Node first;
private Node currentNode;
private int length;
class Node
{
private String data;
private Node next;
public void printNodeData()
{
System.out.println("Node data: " + data);
}
public Node getNext()
{
return next;
}
}
public LinkedStringList()
{
first = null;
currentNode = null;
length = 0;
}
public void addFirst(String value)
{
// create the Node and set its value
Node newNode = new Node();
newNode.data = value;
// if newNode is the first node, this will be null
// otherwise it will point to the former "first" now
newNode.next = first;
// set our "first" Node to the Node we just created
first = newNode;
currentNode = newNode;
length++;
}
public void setFirstValue(String value)
{
first.data = value;
}
public void setCurrentValue(String value)
{
currentNode.data = value;
}
public void moveNext()
{
if (currentNode.next == null)
{
throw new NoSuchElementException();
}
else
{
currentNode = currentNode.next;
}
}
public void moveFirst()
{
currentNode = first;
}
public boolean isEmpty()
{
return (first == null);
}
public int getLength()
{
return length;
}
public String getFirstValue()
{
if (first == null)
{
throw new NoSuchElementException();
}
else
{
return first.data;
}
}
public String getCurrentValue()
{
if (currentNode == null)
{
throw new NoSuchElementException();
}
else
{
return currentNode.data;
}
}
public void displayList()
{
Node currentNode = first;
System.out.println("List contents:");
while (currentNode != null)
{
currentNode.printNodeData();
currentNode = currentNode.getNext();
}
}
public void add(String value) {
Node newNode = new Node();
newNode.data = value;
newNode.next = null;
if (first == null || currentNode == null) {
// create the Node and set its value
// if newNode is the first node, this will be null
// otherwise it will point to the former "first" now
newNode.next = first;
// set our "first" Node to the Node we just created
first = newNode;
} else {
Node curr = first;
while (curr.next != null) {
curr = curr.next;
}
curr.next = newNode;
}
currentNode = newNode;
length++;
}
public void removeFirst() {
if (first == null)
{
throw new NoSuchElementException();
} else if (first == currentNode) {
first = first.next;
currentNode = first;
} else {
first = first.next;
}
}
public void remove() {
if (first == null)
{
throw new NoSuchElementException();
} else if (first.next == null) {
first = null;
currentNode = null;
} else {
Node curr = first, prev = null;
while (curr != currentNode) {
prev = curr;
curr = curr.next;
}
prev.next = curr.next;
currentNode = prev;
}
length--;
}
public int indexOf(String value) {
Node curr = first;
int index = -1;
while (curr != null) {
++index;
if (curr.data.equals(value))
return index;
curr = curr.next;
}
return index;
}
public void sortAscending() {
if (length > 1) {
for (int i = 0; i < length; i++) {
Node currentNode = first;
Node next = first.next;
for (int j = 0; j < length - 1; j++) {
if (currentNode.data.compareTo(next.data) > 0) {
String temp = currentNode.data;
currentNode.data = next.data;
next.data = temp;
}
currentNode = next;
next = next.next;
}
}
}
}
public static void main(String[] args) {
LinkedStringList list = new LinkedStringList();
list.add("First");
list.add("Second");
list.add("Third");
list.displayList();
System.out.println("---------After Modification:--------");
list.moveFirst();
list.setCurrentValue("Red");
list.moveNext();
list.setCurrentValue("Green");
list.moveNext();
list.setCurrentValue("Blue");
list.displayList();
System.out.println("Index of: " + list.indexOf("Green"));
list.displayList();
list.sortAscending();
System.out.println("---------After Sort:--------");
list.displayList();
System.out.println("---------After Removing Twice:--------");
list.remove();
list.remove();
list.displayList();
}
}
Explanation:
import java.util.NoSuchElementException;
public class LinkedStringList {
private Node first;
private Node currentNode;
private int length;
class Node
{
private String data;
private Node next;
public void printNodeData()
{
System.out.println("Node data: " + data);
}
public Node getNext()
{
return next;
}
}
public LinkedStringList()
{
first = null;
currentNode = null;
length = 0;
}
public void addFirst(String value)
{
// create the Node and set its value
Node newNode = new Node();
newNode.data = value;
// if newNode is the first node, this will be null
// otherwise it will point to the former "first" now
newNode.next = first;
// set our "first" Node to the Node we just created
first = newNode;
currentNode = newNode;
length++;
}
public void setFirstValue(String value)
{
first.data = value;
}
public void setCurrentValue(String value)
{
currentNode.data = value;
}
public void moveNext()
{
if (currentNode.next == null)
{
throw new NoSuchElementException();
}
else
{
currentNode = currentNode.next;
}
}
public void moveFirst()
{
currentNode = first;
}
public boolean isEmpty()
{
return (first == null);
}
public int getLength()
{
return length;
}
public String getFirstValue()
{
if (first == null)
{
throw new NoSuchElementException();
}
else
{
return first.data;
}
}
public String getCurrentValue()
{
if (currentNode == null)
{
throw new NoSuchElementException();
}
else
{
return currentNode.data;
}
}
public void displayList()
{
Node currentNode = first;
System.out.println("List contents:");
while (currentNode != null)
{
currentNode.printNodeData();
currentNode = currentNode.getNext();
}
}
public void add(String value) {
Node newNode = new Node();
newNode.data = value;
newNode.next = null;
if (first == null || currentNode == null) {
// create the Node and set its value
// if newNode is the first node, this will be null
// otherwise it will point to the former "first" now
newNode.next = first;
// set our "first" Node to the Node we just created
first = newNode;
} else {
Node curr = first;
while (curr.next != null) {
curr = curr.next;
}
curr.next = newNode;
}
currentNode = newNode;
length++;
}
public void removeFirst() {
if (first == null)
{
throw new NoSuchElementException();
} else if (first == currentNode) {
first = first.next;
currentNode = first;
} else {
first = first.next;
}
}
public void remove() {
if (first == null)
{
throw new NoSuchElementException();
} else if (first.next == null) {
first = null;
currentNode = null;
} else {
Node curr = first, prev = null;
while (curr != currentNode) {
prev = curr;
curr = curr.next;
}
prev.next = curr.next;
currentNode = prev;
}
length--;
}
public int indexOf(String value) {
Node curr = first;
int index = -1;
while (curr != null) {
++index;
if (curr.data.equals(value))
return index;
curr = curr.next;
}
return index;
}
public void sortAscending() {
if (length > 1) {
for (int i = 0; i < length; i++) {
Node currentNode = first;
Node next = first.next;
for (int j = 0; j < length - 1; j++) {
if (currentNode.data.compareTo(next.data) > 0) {
String temp = currentNode.data;
currentNode.data = next.data;
next.data = temp;
}
currentNode = next;
next = next.next;
}
}
}
}
public static void main(String[] args) {
LinkedStringList list = new LinkedStringList();
list.add("First");
list.add("Second");
list.add("Third");
list.displayList();
System.out.println("---------After Modification:--------");
list.moveFirst();
list.setCurrentValue("Red");
list.moveNext();
list.setCurrentValue("Green");
list.moveNext();
list.setCurrentValue("Blue");
list.displayList();
System.out.println("Index of: " + list.indexOf("Green"));
list.displayList();
list.sortAscending();
System.out.println("---------After Sort:--------");
list.displayList();
System.out.println("---------After Removing Twice:--------");
list.remove();
list.remove();
list.displayList();
}
}
Explanation:
I think the answer is: c.
I think the answer is: c.
import java.util.Scanner;
public class CalculatingSales {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int product, quantity;
double total = 0;
while(true) {
System.out.println("Enter product_id and quantity(0 0 to stop): ");
product = sc.nextInt();
quantity = sc.nextInt();
if(product==0 && quantity == 0)
break;
switch (product) {
case 1:
total = total + 2.98*quantity;
break;
case 2:
total = total + 4.50*quantity;
break;
case 3:
total = total + 9.98*quantity;
break;
case 4:
total = total + 4.49*quantity;
break;
case 5:
total = total + 6.87*quantity;
break;
default:
System.out.println("Invalid option");
}
}
System.out.println("total value: "+total);
sc.close();
}
}
Explanation:
Take the product and quantity as input from user.Use a switch statement to multiply the total with their relevant value. Display the total value.import java.util.Scanner;
public class CalculatingSales {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int product, quantity;
double total = 0;
while(true) {
System.out.println("Enter product_id and quantity(0 0 to stop): ");
product = sc.nextInt();
quantity = sc.nextInt();
if(product==0 && quantity == 0)
break;
switch (product) {
case 1:
total = total + 2.98*quantity;
break;
case 2:
total = total + 4.50*quantity;
break;
case 3:
total = total + 9.98*quantity;
break;
case 4:
total = total + 4.49*quantity;
break;
case 5:
total = total + 6.87*quantity;
break;
default:
System.out.println("Invalid option");
}
}
System.out.println("total value: "+total);
sc.close();
}
}
Explanation:
Take the product and quantity as input from user.Use a switch statement to multiply the total with their relevant value. Display the total value.3 ; 5 ; 6 ; 40 ; 150 ; 15; 7.5 ; yes
Step-by-step explanation:
Given the questions:
1. Tara walks a 2 mile route through her neighborhood for daily exercise. It takes her 30 minutes. At this rate, how far can Tara walk in 45 minutes?
Speed = distance / time ; 2 / 0.5 = 4 mph
45 minutes = 0.75 hr
Distance = speed * time = 4 * 0.75 = 3 miles
2. An infant daycare requires 1 teacher for every 4 children. How many teachers are required for 20 children?
1 teacher = 4 children
x = 20 children
x = 20/4 = 5
5 teachers
3. To make purple frosting, you start with white frosting. Then you add 2 drops of red food coloring and 3 drops of blue food coloring. If 4 red drops come out with the first squeeze, how many blue drops should you add?
2 drops of red = 3 drops of blue
4 drops of red = x
x = 12 / 2 = 6 drops of blue
4. Arlen delivers 28 newspapers each morning. The route takes him 40 minutes. If his route increases to 35 newspapers, how long will it take him?
40 minutes
6. On a map, 1 inch represents 50 miles. You measure the distance on the map between two towns as 3 inches How many miles apart are the two towns?
1 inch = 50 miles
3 inch = d
d = 50 * 3 = 150 miles
6. Kelsey earns $5 walking her neighbors' dogs twice a week. At this rate, how much should Kelsey cam if she walks the dogs 6 days each week?
Twice a week = $5
6 times a week = (6/2) * 5 = $15
7. Jeff drove the first 200 miles of a trip in 3 hours. At this rate, how long will the 500 mile trip take, with no stops?
Rate = distance / time = 200 / 3 = 66.667mph
time = 500 /66.667 = 7.5 hours
8. Lisa types 6 pages in 36 minutes. Frank types 5 pages in 30 minutes. Do they type at the same rate?
Lisa's rate :
36 /6 = 6 minutes per page
Frank :
30 /5 = 6 minutes per page
3 ; 5 ; 6 ; 40 ; 150 ; 15; 7.5 ; yes
Step-by-step explanation:
Given the questions:
1. Tara walks a 2 mile route through her neighborhood for daily exercise. It takes her 30 minutes. At this rate, how far can Tara walk in 45 minutes?
Speed = distance / time ; 2 / 0.5 = 4 mph
45 minutes = 0.75 hr
Distance = speed * time = 4 * 0.75 = 3 miles
2. An infant daycare requires 1 teacher for every 4 children. How many teachers are required for 20 children?
1 teacher = 4 children
x = 20 children
x = 20/4 = 5
5 teachers
3. To make purple frosting, you start with white frosting. Then you add 2 drops of red food coloring and 3 drops of blue food coloring. If 4 red drops come out with the first squeeze, how many blue drops should you add?
2 drops of red = 3 drops of blue
4 drops of red = x
x = 12 / 2 = 6 drops of blue
4. Arlen delivers 28 newspapers each morning. The route takes him 40 minutes. If his route increases to 35 newspapers, how long will it take him?
40 minutes
6. On a map, 1 inch represents 50 miles. You measure the distance on the map between two towns as 3 inches How many miles apart are the two towns?
1 inch = 50 miles
3 inch = d
d = 50 * 3 = 150 miles
6. Kelsey earns $5 walking her neighbors' dogs twice a week. At this rate, how much should Kelsey cam if she walks the dogs 6 days each week?
Twice a week = $5
6 times a week = (6/2) * 5 = $15
7. Jeff drove the first 200 miles of a trip in 3 hours. At this rate, how long will the 500 mile trip take, with no stops?
Rate = distance / time = 200 / 3 = 66.667mph
time = 500 /66.667 = 7.5 hours
8. Lisa types 6 pages in 36 minutes. Frank types 5 pages in 30 minutes. Do they type at the same rate?
Lisa's rate :
36 /6 = 6 minutes per page
Frank :
30 /5 = 6 minutes per page
B. Step 2 uses the associative property, and step 3 uses the commutative property.
Step-by-step explanation:
The associative property lets you group terms for addition any way you like. It appears that in Step 2, the grouping is ...
4 + (1/6 + 3) + 5/6
The commutative property lets you change the order of any pair of terms involved in addition. It appears that in Step 3, the order of the terms within the group has been swapped.
4 + (3 + 1/6) + 5/6
Comment on associative and commutative properties
What applies to terms in addition applies to factors in multiplication.
LI*CK MY CU*NT DADDY
Step-by-step explanation:
It will provide an instant answer!