Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Java Assignment Help-Creating a forum
New Posts  All Forums:Forum Nav:

Java Assignment Help-Creating a forum

post #1 of 4
Thread Starter 
Hello,


My assignment is to write a program that is a basic forum, which I'll generate posts with a testClass. I'm having trouble creating a Forum object which will keep track of post objects, where those posts keep track of replies and such - or that's my logic anyways.

The end program needs the posts to be word wrapped to under 50 columns and each reply indented 4 spaces but, I'm not even there yet.tongue.gif

So, can someone help give me a boost? I'm confused with "topics[indexOfPosts] = new Post(subject, contentOfPost, memberOfPost); " What I'm trying to do is add my newly created post object to an array and it comes up with a type mismatch error.


ps

Code:
import java.util.Date;


public class Forum {
        
        private String title;
        private Member member;
        private Date date;
        private String forumOwner;
        private boolean refereed;
        private Forum[] topics;
        private Post post;
        private int indexOfPosts = 0;
        
public Forum(Member member, String title, boolean refereed){
        
        this.title = title;
        this.member = member;
        this.refereed = refereed;
        
}

public Post addPost(String subjectLine, String content, Member member){
        
        String subject = subjectLine;
        String contentOfPost = content;
        Member memberOfPost = member;
        
                
        Forum[] topics = new Forum[10];
        topics[indexOfPosts] = new Post(subject, contentOfPost, memberOfPost);  //An error comes up here
        
        indexOfPosts++;                                  
        
        return post;
}

public void printSummaryPosts(){
        
        for(int i = 0;  i < topics.length(); i++){
                
        }
}

public void printDetailPosts(){
        
}

private void printHeaderLines(String reportType){
        
        String report = reportType;
        String ref;
        
        if(refereed == true){
                
                ref = "Yes";
                
        }else
                
                ref = "No";
        
        System.out.println("            Assignment Discussion Forum           ");
        System.out.printf("                  %s Report   \n", reportType);
        System.out.printf("Owned by: %s                   No Discussions: %3d\n");
        System.out.printf("Created:  " + date + "    Refereed:%3s\n", ref );
        
}

}
Code:
public class Member {
        
        private String member;
        
        
public Member(String member){
        this.member = member;
}

}

Code:
public class Post {
        
        private String subjectLine;
        private String content;
        private Member member;
        private Post[] replies;
        private int indexOfReplies = 0;
        
public Post(String subjectLine, String content, Member member){
        
        this.subjectLine = subjectLine;
        this.content = content;
        this.member = member;
}

public Post addReply(String subjectLine, String content, Member member){
        
        Post reply = new Post("Re: " + subjectLine, content, member);
        replies[indexOfReplies] = reply;
        indexOfReplies++;
        
        return post;
        
}


}

Code:
public class TestForum {
        
        public static void main(String[] args){
                Member john = new Member("John P Smith");
                
                Forum forum = new Forum(john, "Assignment Discussion", true);
        }

}
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 955 Asus M4A89GTD PRO/USB3 AM3 MSI TF III 7950 OC G. Skill Sniper 8GB 
Hard DriveHard DriveOSMonitor
Crucial M4 128GB SSD  WD Caviar Blue 500GB Windows 7 Pro / Arch Linux Dell Ultrasharp U2312hm 
PowerCase
Ocz ModXStream-Pro 500W Fractal Design Define R4 
  hide details  
Reply
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 955 Asus M4A89GTD PRO/USB3 AM3 MSI TF III 7950 OC G. Skill Sniper 8GB 
Hard DriveHard DriveOSMonitor
Crucial M4 128GB SSD  WD Caviar Blue 500GB Windows 7 Pro / Arch Linux Dell Ultrasharp U2312hm 
PowerCase
Ocz ModXStream-Pro 500W Fractal Design Define R4 
  hide details  
Reply
post #2 of 4
Your topics is a forum array
so that is why
Code:
topics[indexOfPosts] = new Post(subject, contentOfPost, memberOfPost);
gives that error
so Did you intend your post class to be extended from forum? Or did you intend your array to be a post array?? or something else?
Teh computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q8400 MSI MS-7529 HIS icoolerIV 5750 1GB @ 822/1250 Corsair DDR2 2x2 gig 
Hard DriveOSMonitorPower
500 gig HDD SATA @ 7200 rpm Windows 7 32 bit / Ubuntu 10.10 32 bit AOC 22" WLED 1680x1050 Aywun 480W 
Case
Gigabyte gz-x4 
  hide details  
Reply
Teh computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q8400 MSI MS-7529 HIS icoolerIV 5750 1GB @ 822/1250 Corsair DDR2 2x2 gig 
Hard DriveOSMonitorPower
500 gig HDD SATA @ 7200 rpm Windows 7 32 bit / Ubuntu 10.10 32 bit AOC 22" WLED 1680x1050 Aywun 480W 
Case
Gigabyte gz-x4 
  hide details  
Reply
post #3 of 4
Thread Starter 
Well, I want topics[] to hold post objects. So, I should declare it as a Post type array?
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 955 Asus M4A89GTD PRO/USB3 AM3 MSI TF III 7950 OC G. Skill Sniper 8GB 
Hard DriveHard DriveOSMonitor
Crucial M4 128GB SSD  WD Caviar Blue 500GB Windows 7 Pro / Arch Linux Dell Ultrasharp U2312hm 
PowerCase
Ocz ModXStream-Pro 500W Fractal Design Define R4 
  hide details  
Reply
My System
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 955 Asus M4A89GTD PRO/USB3 AM3 MSI TF III 7950 OC G. Skill Sniper 8GB 
Hard DriveHard DriveOSMonitor
Crucial M4 128GB SSD  WD Caviar Blue 500GB Windows 7 Pro / Arch Linux Dell Ultrasharp U2312hm 
PowerCase
Ocz ModXStream-Pro 500W Fractal Design Define R4 
  hide details  
Reply
post #4 of 4
Quote:
Originally Posted by Multiverse View Post

Well, I want topics[] to hold post objects. So, I should declare it as a Post type array?

If you want it to hold post objects, then yes, changing it to a Post array should work.
Teh computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q8400 MSI MS-7529 HIS icoolerIV 5750 1GB @ 822/1250 Corsair DDR2 2x2 gig 
Hard DriveOSMonitorPower
500 gig HDD SATA @ 7200 rpm Windows 7 32 bit / Ubuntu 10.10 32 bit AOC 22" WLED 1680x1050 Aywun 480W 
Case
Gigabyte gz-x4 
  hide details  
Reply
Teh computer
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q8400 MSI MS-7529 HIS icoolerIV 5750 1GB @ 822/1250 Corsair DDR2 2x2 gig 
Hard DriveOSMonitorPower
500 gig HDD SATA @ 7200 rpm Windows 7 32 bit / Ubuntu 10.10 32 bit AOC 22" WLED 1680x1050 Aywun 480W 
Case
Gigabyte gz-x4 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Java Assignment Help-Creating a forum