
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
How do I match the output?
Code:
import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;
public class Assignment08
{
public static void main(String[] args) throws Exception
{
File inputData = new File("input05.txt");
Scanner input = new Scanner(inputData);
int totalNumber = input.nextInt();
Friend.friends = new Friend[totalNumber];
input.nextLine();
for (int i = 0; i < totalNumber; i++)
{
String name = input.nextLine();
String phone = input.nextLine();
String age = input.nextLine();
int ageNum = Integer.parseInt(age);
Friend.friends[i] = new Friend(name, phone, ageNum);
}
printContacts(Friend.friends);
Friend.showTotalFriendAge();
ManageDuplicate(Friend.friends);
printContacts(Friend.friends);
Friend.showTotalFriendAge();
}
public static void printContacts(Friend[] contacts)
{
System.out.println("Contacts (" + contacts.length + ")");
System.out.println("===================");
for (Friend friend : contacts)
{
System.out.println(friend);
}
System.out.println();
}
public static void ManageDuplicate(Friend[] contacts)
{
ArrayList<Friend> duplicates = new ArrayList<>();
for (int i = 0; i < contacts.length - 1; i++)
{
for (int j = i + 1; j < contacts.length; j++)
{
if (contacts[i].equals(contacts[j]))
{
duplicates.add(contacts[i]);
}
}
}
if (!duplicates.isEmpty())
{
System.out.println("Duplicate contact detected:");
for (int i = 0; i < duplicates.size(); i++)
{
System.out.println("(" + i + ")" + duplicates.get(i).getName());
}
System.out.println();
// Modify duplicate entries and set age to 0
for (Friend duplicate : duplicates)
{
duplicate.setAge(0);
}
}
}
}
public class Friend
{
private String name;
private String phone;
private int age;
public static Friend[] friends; //array
public String toString()
{
return String.format("Name: %-20sPhone: %-15sAge: %d", name, phone, age);
}
public Friend(String name)
{
this.name = name;
}
public Friend(String name, String phone)
{
this.name = name;
this.phone = phone;
}
public Friend(String name, String phone, int age)
{
this.age = age;
this.name = name;
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean equals(Friend dest)
{
if(this.name.equals(dest.name) && this.phone.equals(dest.phone) && this.age == dest.age)
{
return true;
}
else
{
return false;
}
}
public static void showTotalFriendAge()
{
int totalAge = 0;
System.out.print("Total Friends Age:(");
for(int i = 0; i < friends.length; i++)
{
if(i < friends.length - 1)
{
System.out.print(friends[i].age + ",");
}
else
{
System.out.print(friends[i].age + "");
}
totalAge += friends[i].age;
}
System.out.print(") Total: " + totalAge);
}
public static int getNumFriends()
{
return 0;
}
}

Transcribed Image Text:Contacts (12)
====
Name: Albert Zoe
Name: Albert Zoe
Name: Cat Xiver
Name: Dan Woow
Name: Esther Uno
Name: Frankie Uion
Name: Albert Zoe
Name: Gab Xvy
Name: Henrik Que
Name: Albert Zoe
Name: Henrik Que
Name: Henrik Que
Total Friends Age: (10,44,20,2,16,10,10,12,11,10,11,12) Total: 168
Duplicate contact detected: (0)Albert Zoe and (6) Albert Zoe
Duplicate contact detected: (0)Albert Zoe and (9)Albert Zoe
Duplicate contact detected: (8)Henrik Que and (10) Henrik Que
Contacts (12)
========
======
Phone: 8581234567
Phone: 8581234567
Phone: 6193456789
Phone: 8584567891
Phone: 8584567890
Phone: 4294567123
Phone: 8581234567
Phone: 6184567234
Phone: 7604567345
Phone: 8581234567
Phone: 7604567345
Phone: 7604567345
Age: 10
Age: 44
Age: 20
Age: 2
Age: 16
Age: 10
Age: 10
Age: 12
Age: 11
Age: 10
Age: 11
Age: 12
Name: Albert Zoe
Name: Albert Zoe
Name: Cat Xiver
Name: Dan Woow
Name: Esther Uno
Name: Frankie Uion
Name: Albert Zoe (1)
Name: Gab Xvy
Name: Henrik Que
Name: Albert Zoe(2)
Name: Henrik Que(3)
Name: Henrik Que
Total Friends Age: (44,20,2,16,10,12,10,11,12,0,0,0) Total: 137
Phone: 8581234567
Phone: 8581234567
Phone: 6193456789
Phone: 8584567891
Phone: 8584567890
Phone: 4294567123
Phone: 8581234567(1)
Phone: 6184567234
Phone: 7604567345
Phone:
Age: 11
8581234567(2) Age: 0
Phone: 7604567345(3) Age: 0
Phone: 7604567345
Age: 12
Age: 10
Age: 44
Age: 20
Age: 2
Age: 16
Age: 10
Age: 0
Age: 12
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps

Knowledge Booster
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
- What is wrong with this code it creates a file Exercise17_1 but no input into the file? package randomintegers; import java.io.*;import java.util.*; public class RandomIntegers { public static void main(String[] args)throws Exception{ PrintWriter out = new PrintWriter(new FileOutputStream("Exercise17_1.txt",(true)); { for(int j=0;j<100; j++) out.print((int)(Math.random()*100000)+""); } }}arrow_forwardJava Program ASAP Modify this program so it passes the test cases in Hypergrade becauses it says 5 out of 7 passed. Also I need one one program and please correct and change the program so that the numbers are in the correct places as shown in the correct test case. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.InputMismatchException;import java.util.Scanner;public class FileSorting { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please enter the file name or type QUIT to exit:"); String fileName = scanner.nextLine(); if (fileName.equalsIgnoreCase("QUIT")) { break; } try { ArrayList<String> lines = readFile(fileName); if (lines.isEmpty()) { System.out.println("File " +…arrow_forwardIm trying ro read a csv file and store it into a 2d array but im getting an error when I run my java code. my csv file contains 69 lines of data Below is my code: import java.util.Scanner; import java.util.Arrays; import java.util.Random; import java.io.File; import java.io.FileNotFoundException; import java.io.FilenameFilter; public class CompLab2 { public static String [][] getEarthquakeDatabase (String Filename) { //will read the csv file and convert it to a string 2-d array String [][] Fileinfo = new String [69][22]; int counter = 0; File file = new File(Filename); try { Scanner scnr = new Scanner(file); scnr.nextLine(); //skips the label in the first row of the file while (scnr.hasNextLine()) { // this while loop will count the number of values in the usgs file counter += 1; // increases by one each time a line is read scnr.nextLine(); } while…arrow_forward
- FilelO 01: Write a Message Write a FileI001 class with a method named writeMessage() to takes message as a String and a filename (as a String) (in that order). Have the method, write the message to the filename. Your code will either need to 1) catch all checked exceptions or 2) use the throws keyword. public class FileI001{ public void writeMessage( String message, String filename ){arrow_forward-Add a method to the tractor class to write all of atractors attributes to a text file. Name it saveData(Stringfilename) It should throw Exceptions.-Add a method to the tractor class to read all of atractors attributes from a text file. Name itloadData(String filename) It should throw Exceptions.-Test these methods by calling them from your testdrivers main() method public class Tractor { private String ID; private double rentalRate; private int rentalDays; Tractor() { this.ID = "00"; this.rentalDays = 0; this.rentalRate = 0; } } Tractor(String ID, double rentalRate, int rentalDays) { this.setID(ID); this.setRentalDays(rentalDays); this.setRentalRate(rentalRate); } /** * @return the iD */ public String getID() { return ID; } /** * @return the rentalDays */ public int getRentalDays() { return rentalDays; } /** * @return the rentalRate */…arrow_forwarddef analyze_file (filename: str, pos_words: List [str], neg_words: List [str]) -> Given the name of a file, a list of positive words (all in lowercase), and a list of negative words (all in lowercase), return some interesting data about the file in a tuple, with the first item in the tuple being the positivity score of the contents of this file, and the rest of the item: being whatever else you end up analyzing. (Helper functions are highly encouraged here.) How to calculate positivity score: For every word that is pos itive in the file (based on the words in the list of positive words) add 1 to the score. For every negative word (based on the list of negative words), subtract 1 from the score. Any neutral words (those that do not appear in either list) do not affect the score in any way. passarrow_forward
- I need help with this code !! import java.util.Arrays;import java.util.Scanner; public class MaxElement {public static void main(String[] args) { //create an object for Scanner class Scanner x = new Scanner (System.in);System.out.print ("Enter 10 integers: ");// create an arrayInteger[] arr = new Integer[10]; // Execute for loopfor (int i = 0; i < arr.length; i++) {//get the 10 integersarr[i] = x.nextInt(); } // Print the maximum numberSystem.out.print("The max number is = " + max(arr));System.out.print("\n"); } //max method public static <E extends Comparable<E>> E max(E[] arr) {E max = arr[0]; // Execute for loop for (int i = 1; i < arr.length; i++) { E element = arr[i];if (element.compareTo(max) > 0) {max = element;}}return max; }}arrow_forwardmain.py Load default template... 1 from random import randint 3 class RandomNumbers: # Type your code here. 4 5 main ": 6 if low = int(input()) high = int(input()) name 7 8 9 numbers = RandomNumbers() numbers. set_random_values(low, high) numbers.get_random_values() 10 11 12arrow_forwardFirst, create the custom exception class called OutOfStockException by creating a new class that extends the Exception class The class has a single constructor that takes a single argument, a string called message. The message argument is passed to the parent class (Exception) via the super keyword. Create the Store class and import the java.util.HashMap and java.util.Map classes The Store class is defined with a private Map called products, which is used to store the product names and their corresponding quantities. Create a default constructor that initializes the products map with three items: "apple", "banana", and "orange", with respective quantities of 10, 5, and 0. Define thepurchase method , which takes two arguments: a product name and a quantity to be purchased. This method throws an OutOfStockException if either the specified product is not available in the store or if the requested quantity is greater than the quantity available in stock. The method first…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education