Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public class Newsfeed {
  2.  
  3. String[] topics = {"Opinion", "Tech", "Science", "Health"};
  4. int[] views = {0, 0, 0, 0};
  5.  
  6. public Newsfeed(){
  7. }
  8. public String[] getTopics(){
  9. return topics; }
  10. public String getTopTopic(){
  11. return topics[0];
  12. }
  13. public void viewTopic(int topicIndex){
  14. views[topicIndex] = views[topicIndex] + 1; //dlaczego array inkrementuje się w ten sposób?
  15. views[] = views[] + 1; //a nie w ten?
  16. views[] = topicIndex;
  17. topicIndex = topicIndex + 1; //albo w ten?
  18. }
  19. public static void main(String[] args){
  20. Newsfeed sampleFeed = new Newsfeed();
  21. System.out.println("The top topic is "+ sampleFeed.getTopTopic());
  22. sampleFeed.viewTopic(1);
  23. sampleFeed.viewTopic(1);
  24. sampleFeed.viewTopic(3);
  25. sampleFeed.viewTopic(2);
  26. sampleFeed.viewTopic(2);
  27. sampleFeed.viewTopic(1);
  28. System.out.println("The " + sampleFeed.topics[1] + " topic has been viewed " + sampleFeed.views[1] + " times!");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement