write java program to manage documents in a company,
using Arraylist in java.
package com.mycompany.cis104; import java.util.Date; /** * * @author ads21 */ class Document { private String[] authors; private Date date; private int authorsCounter; public Document() { authors=new String[5]; authorsCounter=0; } public String[] getAuthors() { return authors; } public void addAuthor(String name) { if(authorsCounter<authors.length) { authors[authorsCounter]=name; authorsCounter++; } else System.out.println("authors array is full!"); } public Date getDate() { return date; } } class Book extends Document { private String title; public String getTitle() { return title; } } class Email extends Document { private String subject; private String[] to; public String getSubject() { return subject; } public String[] getTo() { return to; } } class DocumentManagementSystem { public static void main(String[] args) { Document doc1=new Document(); doc1.addAuthor("fathi"); doc1.addAuthor("adnan"); doc1.addAuthor("omar"); System.out.println("authors list:"); String a[]=doc1.getAuthors(); for(int i=0;i<a.length;i++) System.out.println(a[i]); } }
package com.mycompany.cis104; import java.util.ArrayList; import java.util.Scanner; public class ArrayListClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter 3 numbers: "); ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < 3; i++) list.add(input.nextInt()); System.out.println("Sorting numbers..."); sort(list); System.out.println("Displaying numbers..."); System.out.println(list); System.out.println("the summation of numbers in list is : "+sum(list)); } public static void sort(ArrayList<Integer> list) { // simple solution //list.sort(null); // manual solution for (int i = 0; i < list.size() - 1; i++) { int currentMin = list.get(i); int currentIndex = i; for (int j = i + 1; j < list.size(); j++) { if (currentMin > list.get(j)) { currentMin = list.get(j); currentIndex = j; } } if (currentIndex != i) { list.set(currentIndex, list.get(i)); list.set(i, currentMin); } } } public static Integer sum( ArrayList<Integer> list){ Integer summation=0; for(Integer x:list) { summation=summation+x; } return summation; } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
need an explanation for this answer? contact us directly to get an explanation for this answer