Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
public class Main
{
public static void main(String args[])
{
Main m = new Main();
m.go();
}
public void go()
{
Customer c = new Customer("Tom", "Smith");
Order o = new Order(c);
o.addItem(new Item("Greeting Card", 1.50, 1));
o.addItem(new Item("Baseball Glove", 54.00, 1));
o.addItem(new Item("Notebook", 2.50, 3));
System.out.println(o);
}
}
Expert Solution
arrow_forward
Explaination
Here is the step by step instructions
- Make sure that all the files are in the same folder and mentioned the statment package folderName; at start of every java file as there are 4 java files one for customer, one for item ,one for order, one for main java class
- We just had to create the two classes customer and item which have the constructor to initilize the object data members of the class and to string method to give the string representation of the class
- In the order class we have addItem method in which we have to add the item in the list of item . Hence use the method add to add the item in the list of items.
- Then we have to create the to string method
- Apply the for loop on the arraylist m_items to call the to string method on every item object in the list
- Call the to string method of the customers class to get the name of the person
- Check the code comments as everything is mentioned into that clearly .
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 6 images
Knowledge Booster
Similar questions
- public class KnowledgeCheckTrek { public static final String TNG = "The Next Generation"; public static final String DS9 = "Deep Space Nine"; public static final String VOYAGER = "Voyager"; public static String trek(String character) { if (character != null && (character.equalsIgnoreCase("Picard") || character.equalsIgnoreCase("Data"))) { // IF ONE return TNG; } else if (character != null && character.contains("7")) { // IF TWO return VOYAGER; } else if ((character.contains("Quark") || character.contains("Odo"))) { // IF THREE return DS9; } return null; } public static void main(String[] args) { System.out.println(trek("Captain Picard")); System.out.println(trek("7 of Nine")); System.out.println(trek("Odo")); System.out.println(trek("Quark")); System.out.println(trek("Data").equalsIgnoreCase(TNG));…arrow_forwardint machineCompare1(struct machine* mac1, struct machine* mac2){ struct mac1; struct mac2; char make1[21], make2[21]; char model1[51], model2[21]; if((lap1 -> make1 == lap2 -> make2) && (lap1 -> model1 == lap2 -> model2)) return 0; else return 1;} have to create function to compare make and model of 2 machines - it's using structures - not sure if this is correct/ on the right track?arrow_forwardC++ Program #include <iostream>#include <cstdlib>#include <ctime>using namespace std; int getData() { return (rand() % 100);} class Node {public: int data; Node* next;}; class LinkedList{public: LinkedList() { // constructor head = NULL; } ~LinkedList() {}; // destructor void addNode(int val); void addNodeSorted(int val); void displayWithCount(); int size(); void deleteAllNodes(); bool exists(int val);private: Node* head;}; // function to check data exist in a listbool LinkedList::exists(int val){ if (head == NULL) { return false; } else { Node* temp = head; while (temp != NULL) { if(temp->data == val){ return true; } temp = temp->next; } } return false;} // function to delete all data in a listvoid LinkedList::deleteAllNodes(){ if (head == NULL) { cout << "List is empty, No need to delete…arrow_forward
- OOP (Object-Oriented Programming) in Java Applying the composite pattern, you may create a replica of any environment you choose. Any number of media may be used, from photographs to simulators to movies to video games, and so on.arrow_forwardJava - When too many recursive calls are made creating more activation records than the allocated program memory can handle, an “out of memory” error occurs. True or False?arrow_forwardUML DIAGRAM FOR THE FOLLOWING public class BookStore { /** * @param args the command line arguments */ Customer customerList[]; Product productList[]; public static void main(String[] args) { // TODO code application logic here } public Customer registerPremiumMember(){ Customer newCustomer = new Customer(); return newCustomer; } public void completePurchase(Customer coCustomer){ } public Customer addToBasket(Customer currentCustomer, Product cuProduct){ currentCustomer.addToBasket(cuProduct); return currentCustomer; }}arrow_forward
- Demonstrate Recursion Assignment Instructions Overview The programs we’ve discussed so far are generally structured as methods that call one another in a hierarchical manner. For some problems, it’s useful to have a method call itself—this is known as a recursive method. Such a method can call itself either directly or indirectly through another method. Recursion is an important topic discussed at length in upper-level computer-science courses. Instructions Write a recursive method printArray() that displays all the elements in an array of integers, separated by spaces. The array must be 100 elements in size and filled using a for loop and a random number generator. The pseudo-code for this is as follows: //Instantiate an integer array of size 100 //fill the array For (int i=0; i<array.length; i++) Array[i] = random number between 1 and 100 inclusive printArray(integer array); For this assignment make sure that your screen shots show your program running and that your runtime…arrow_forwardcomplete the missing code. public class Exercise09_04Extra { public static void main(String[] args) { SimpleTime time = new SimpleTime(); time.hour = 2; time.minute = 3; time.second = 4; System.out.println("Hour: " + time.hour + " Minute: " + time.minute + " Second: " + time.second); } } class SimpleTime { // Complete the code to declare the data fields hour, // minute, and second of the int type }arrow_forwardQuestion 13 What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle= = new Plane(); myVehicle.drive(); } Driving vehicle syntax error Flying plane Driving vehicle Flying plane }arrow_forward
- public class Course{String name;String dept;int number;public Course (String n, String d, int n){name = n;dept = d;number = n;}public String toString(){return "Course " + name + " in " + dept + " #: " + number;}public static void main (String [] args){Scanner in = new Scanner(System.in);add 10 lines using the scanner and saving them as strings The input for each line will be entered a String, a space, another String, and an int. Parse the input string into those three items and make an instance of Course. Add the new Course instance to a generic ArrayList of Course. print out each Course in the ArrayList.arrow_forwardpublic class Ex08FanTest { public static void main (String[] args){ Ex08Fan fan1= new Ex08Fan(); Ex08Fan fan2= new Ex08Fan(); fan1.setOn(true); fan1.setSpeed(3); fan1.setRadius(10); fan1.setColor("yellow"); fan2.setOn(true); fan2.setSpeed(2); fan2.setRadius(5); fan2.setColor("blue"); fan2.setOn(false); System.out.println("Fan 1:\n" + fan1.toString()); System.out.println("\nFan 2:\n" + fan2.toString()); }}arrow_forwardPROBLEM STATEMENT: Return a number, 1 lesser than the given number. public class Decrement{public static int solution(int x){// ↓↓↓↓ your code goes here ↓↓↓↓return 0;}} Can you please use The source code i providedarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY