New Posts  All Forums:Forum Nav:

Java assignment help ASAP

post #1 of 4
Thread Starter 
http://www.mediafire.com/?2lqh6z3uexm8282
post #2 of 4
Thread Starter 
I swear it's not a virus just a pdf file i can't convert :3
post #3 of 4
for reference, this is the assignment.
Quote:
Write a program that prints a diamond with a plus within it, given the height of the diamond. The outer-most shape is a normal
diamond shape, the middle row of the shape will be a row filled with stars (making the horizontal dash of the plus sign), and in
all the remaining rows the middle element of that row will have a star (making the vertical dash of the plus sign). Observe the
following examples.

you need to start by figuring out the pattern for each row. for example with n=11, row 0 has 5 leading spaces followed by 1 star. 5=n/2. the middle row and last are similarly very easy. the rows in between always have 3 stars, separated by a number that is related to the row number.

here is some pseudocode to get you started. i believe my logic is correct.
Code:
string toprint = "";
// for each row
for(int row=0; row<n; row++){        
        toprint = "";
        if(row==0){
                // leading spaces = n/2
                foreach(0 to n/2) toprint += " ";
                toprint += "*";
        }
        else if((row>0)&&(row<n/2)){
                // leading spaces = n/2 - row number
                foreach((n/2)-row) toprint += " ";
                
                // 3 stars in each row>0 && row < n/2
                for(int i=0; i<3; i++){
                        toprint +="*";
                        string spaces = "";
                        
                        // spaces between stars = row number -1
                        foreach(0 to row-1) spaces += " ";
                        toprint += spaces;
                }
        }
        else if(row==n/2){
                foreach(0 to n){
                        toprint += "*";
                }
        }
        else if((row>n/2)&&(row<n-1)){
                foreach(0 to row-(n/2)) toprint += " ";
                
                // 3 stars in each row>n/2 && row < n-1
                for(int i=0; i<3; i++){
                        toprint +="*";
                        string spaces = "";
                        
                        // spaces between stars = n - row number-2
                        foreach(0 to n-row-2) spaces += " ";
                        toprint += spaces;
                }
        }
        else if(row==n-1){
                // leading spaces = n/2
                foreach(0 to n/2) toprint += " ";
                toprint = "*";
        }
        toprint += "\n";
}
print(toprint);

EDIT: just to double check that my logic is correct, i converted my pseudocode to c++ and it works.
Edited by travesty - 3/27/12 at 2:07pm
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #4 of 4
Thread Starter 
thnkx soo much i will try to convert it as i'm a beginner but thankx anyways smile.gif
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming