![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 5
| call a method from another to a class Code:
public class Display
{
void display(String heading)
{
System.out.println("My name is bob.");
}
}
then call it from this class Code:
public class CallDisplay
{
public static void main(String[]args)
{
Display print = new Display();
print.display();
System.out.print(print);
}
}
|
| vipur is offline | |
| | #2 |
| Registered User Join Date: Nov 2009
Posts: 5
| hey peeps, i have a really big probelemo...i'm in grade 11 and writing i.t p1 prac on monday and still dunno how to call a method from another to a class.....im trying to create a simple program........ [code] public class Display { void display(String heading) { System.out.println("My name is bob."); } } [\code] then call it from this class Code:
public class CallDisplay
{
public static void main(String[]args)
{
Display print = new Display();
print.display();
System.out.print(print);
}
}
|
| vipur is offline | |
| | #3 | |
| Registered User Join Date: Sep 2006
Posts: 3,157
| Quote:
1) Start your *own* thread, for your problem. With very few exceptions, you'll be way better off. 2) Get into the *right* forum. ![]() This is the C forum, not the C++ forum, and C doesn't have classes at all. Get over to our C++ forum. Eman: ==== For school assignments, I prefer Borland Turbo C/C++, myself. That's what I used to work on your program, btw. I believe if you add a few things to the program I pared down for you, you'll have better luck than trying to use the bloated program, as the "backbone", and just trim it down and make it work right. I killed it (your old program), at least once, trying to get it whittled down in size. ![]() If you have any further questions, post up your current version so I'll know where you're at. Last edited by Adak; 11-14-2009 at 04:47 PM. | |
| Adak is offline | |
| | #4 |
| Registered User Join Date: Sep 2006
Posts: 3,157
| And *AGAIN*, you're in the WRONG FORUM! And don't hijack other posters threads - start your own, and do it in the right forum (C++). |
| Adak is offline | |
| | #5 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,372
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #6 | |
| Registered User Join Date: Nov 2009
Posts: 17
| Quote:
I have an idea..what if i use cases for num1 like case 1: for() case2: for() and generate different questions..but the cases would have different operators.like case1, plus, case 2, minus or times and so on.. at least that way..the code would be way shorter than before..what dou think? | |
| Eman is offline | |
| | #7 | |
| Registered User Join Date: Nov 2009
Posts: 17
| Quote:
Code: #include <stdio.h>
#include <conio.h>
#include <stdlib.h>
/*this code is for to ask a number of questions in a quiz contest re-displaying a menu */
main()
{
int i ;
int one=2, two=3, three=4, four=5 ;
int answer1 = 2 ;
int answer2 = 9 ;
int answer3 = 24;
int answer4 = 100;
char yesno ;
int num1 = 0;
int option = 0 ;
do
{
printf(" \n ") ;
printf(" ((----))\n") ;
printf(" <--<\\\\_//>->\n") ;
printf(" | | \n") ;
printf(" (===)\n") ;
printf("\n") ;
printf(" QUIZZITCH CUP\n") ;//This is just some drawing of the prize cup that the winner would have
printf("\n") ;
printf("1. Enter the number of questions to be asked for this round of the quiz\n") ;
printf("2. Start quiz\n") ;
printf("3. Display the numbers of questions that were (i) correctly (ii) incorrectly\n") ;
printf("4. Exit Program\n") ;
scanf("%d", &option) ;//waits for an input for 1, 2, 3 or 4
while(option != 1&&option!=4&&option!=3) //if option is not =1 it willforce user to enter1. but if user chooses 3..it would go to the other while loop//this enables it to display the results of option3 if variable num1 isn't empty. if it is empty and user chose 3..then menu would be redisplayed
{
printf("You must choose 1 before you can proceed to quiz\n") ;
scanf("%d", &option) ;
if(option==4)
{
return 0 ;
break ;
}
i++ ;
}
switch(option) //the switch option allows me to choose number of questions i want .
{
case 1:
{
printf("1. One question\n") ;
printf("2. Two questions\n") ;
printf("3. Three questions\n") ;
printf("4. Four questions\n") ;
scanf("%d", &num1) ; //this scanf to read in the option for the number questions to be answered
while(num1 != 1 && num1 != 2&& num1 != 3 && num1 != 4)
{
printf("You must choose from 1-4 before you can proceed to quiz\n") ;
scanf("%d", &num1) ;
i++ ;
}
clrscr() ;
}
case 2:
{
switch(num1)//start of option 2 using num1 as a variable of numbers of questions to be asked
{
case 1:
{
printf("What is 1+1: *\n") ;
scanf("%d", &answer1) ;//the answer is stored in a variable one, two, three, four, and matched with answer1-5. if it matches..then result is display
break;
}//end of case 1 of question 1
case 2:
{
for(i=0; i<num1; one++, i++)
{
printf("what is %d * %d\n", one, (i+1*3)) ;
scanf("%d", &answer2) ;
}
break ;
}//end of question 2
//case 3
case 3:
{
for(i=0; i<num1; i++)
{
printf("what is %d - %d\n",(one*2)-(i-3), one*=2) ;
scanf("%d", &answer3) ;
}
break ;
}
case 4:
{
for(i=0; i<num1; i++,four+=3)
{
printf("what is %d * %d\n", four, (four*2)-(i+3)) ;
scanf("%d", &answer4) ;
}
break ;
}
}
break ;
}//end of case 2 of switch(option)
case 3: //beginning of case 3. case 3 shows how many questions the user answer correctly
{
if(option == 3 && num1 == 0)
{
printf("You haven't answered question\n") ;
break ;
}
if(num1==1)
{
//by checking the various possibilities the user could have answered the question
if(one==2)
{
printf("i. You got 1 Correct!\n") ;
}
else
{
printf("ii. You got 1 Incorrect!!\n") ;
}
break ;
}
if(num1==2)
{
if(one == 2 && two == 9)
{
printf("i. You got 2 Correct!\n") ;
printf("ii. You got none Incorrect!!\n") ;
}
else if(one == 2 && two!= 9||one!=2 && two == 9)
{
printf("i. You got 1 Correct!\n") ;
}
else
{
printf("ii. You got Everything Incorrect!!\n") ;
}
break ;
}
if(num1==3)
{
if(one != 2 && two !=9 && three == 24||one != 2 && two == 9 && three != 24||one == 2 && two != 9 && three != 24)
{
printf("i. You got 1 Correct!\n") ;
printf("ii. You got 2 Incorrect!!\n") ;
}
else if(one == 2 && two == 9 && three != 24||one != 2 && two == 9 && three == 24||one == 2 && two != 9 && three == 24)
{
printf("i. You got 2 Correct!\n") ;
printf("ii. You got 1 Incorrect!!\n") ;
}
else if(one==2 && two==9 && three==24)
{
printf("i. You got Everything Correct\n") ;
}
else
{
printf("i. You got Everything Incorrect!!\n") ;
}
}
if(num1==4)
{
if(one == 2 && two !=9 && three != 24 && four != 100||one != 2 && two == 9 && three != 24 && four != 100||one != 2 && two != 9 && three == 24 && four!= 100||one != 2 && two != 9 && three != 24 && four==100)
{
printf("i. You got 1 correct!\n") ;
printf("ii. You got 3 incorrect!!\n") ;
}
else if(one != 2 && two != 9 && three == 24 && four == 100||one == 2 && two == 9 && three != 24 && four != 100|| one != 2 && two == 9 && three == 24 && four != 100|| one == 2 && two != 9 && three != 24 && four == 100)
{
printf("i. you got 2 correct\n") ;
printf("ii. you got 2 incorrect\n") ;
}
else if(one != 2 && two == 9 && three == 24 && four == 100||one == 2 && two != 9 && three == 24 && four == 100||one == 2 && two == 9 && three != 24 && four== 100||one == 2 && two == 9 && three == 24 && four!= 100)
{
printf("i. You got 3 Correct!\n") ;
printf("ii. You got 1 Incorrect!!\n") ;
}
else if(one == 2 && two == 9 && three == 24 && four == 100)
{
printf("i. You got everything Correct\n") ;
}
else
{
printf("i. you got everything Incorrect\n") ;
}
break;
}
break ;
}//end of switch(num1)
case 4:
{
printf("Are you sure you want to exit quiz?\n") ;
printf("Y/N") ;
printf("\n") ;
scanf("%1s", &yesno) ;
if(yesno== 'Y'|| yesno == 'y')
{
exit(0) ;
}
clrscr() ;
break ; /*user must input y to quit*/
}
default:
{
printf("Can't you follow simple instructions?\n") ;
break ;
}
}
}while(option==1 || option==2 ||option==3 || option == 4) ;
getch() ;
}
yeah Borland C..is alright..but it is dimmer and makes my eyes sore..how didu get visual studio or C++ to compile for u? it doesnt work for me | |
| Eman is offline | |
| | #8 |
| Registered User Join Date: Nov 2009
Posts: 5
| lol sorry, i just like registered yday so i like looked everywhere for creating my own thread, counldn't find it lol.........but thanks, il post in c++ |
| vipur is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting an error with OpenGL: collect2: ld returned 1 exit status | Lorgon Jortle | C++ Programming | 6 | 05-08-2009 08:18 PM |
| Dikumud | maxorator | C++ Programming | 1 | 10-01-2005 06:39 AM |
| Having a class function call a function outside the class | Aeroren | C++ Programming | 2 | 08-09-2005 06:33 AM |
| problem with sending files to a class method.. | utoots | C++ Programming | 5 | 04-02-2003 01:38 AM |
| Pls help me to do this project in C I need source code | sureshmenon74 | C Programming | 4 | 10-04-2001 06:57 AM |