Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Newsfeed {
- String[] topics = {"Opinion", "Tech", "Science", "Health"};
- int[] views = {0, 0, 0, 0};
- public Newsfeed(){
- }
- public String[] getTopics(){
- return topics; }
- public String getTopTopic(){
- return topics[0];
- }
- public void viewTopic(int topicIndex){
- views[topicIndex] = views[topicIndex] + 1; //dlaczego array inkrementuje się w ten sposób?
- views[] = views[] + 1; //a nie w ten?
- views[] = topicIndex;
- topicIndex = topicIndex + 1; //albo w ten?
- }
- public static void main(String[] args){
- Newsfeed sampleFeed = new Newsfeed();
- System.out.println("The top topic is "+ sampleFeed.getTopTopic());
- sampleFeed.viewTopic(1);
- sampleFeed.viewTopic(1);
- sampleFeed.viewTopic(3);
- sampleFeed.viewTopic(2);
- sampleFeed.viewTopic(2);
- sampleFeed.viewTopic(1);
- System.out.println("The " + sampleFeed.topics[1] + " topic has been viewed " + sampleFeed.views[1] + " times!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement