Ganjaran Bonus Forex Yang Terbesar Tidak Pernah Ditawarkan Sebelum ini ... BONUS TANPA SEBARANG DEPOSIT SEBANYAK $1500 DARI INSTAFOREX !!


Go Back   CariGold Forum > COMPUTER, INTERNET > Webmaster, Blogger Discussion > Programming, Web Development

Recommended Brokers

Forex Chart
Crypto Chart
CG Sponsors



Reply
 
Thread Tools
  #1  
Old 22-06-2018, 10:21 AM
TyCo86 TyCo86 is offline
Regular

TyCo86's Avatar
 
Trader Rating: (0)
Join Date: Sep 2013
Posts: 227
Thanks (Received): 0
Likes (Received): 0
Blog Entries: 1
Active Level
My Mood:
Default Soalan Java Programming

Assalammualaikum kepada member2 CG yang expert dlm Java. Boleh berikan bantuan untuk jawab soalan Java di bawah nie?

Write a program in Java called Marks, which prompts user for the number of marks, reads it from the keyboard, and saves it in an int variable called numOfMarks. It then prompts user for the marks and saves them in an int array called marks. Your program shall check that the marks value is between 0 and 100 and the number of marks is between 1 to 30. The program should display number of marks that are more than 50. An example of output is shown below:


Enter the number of marks: 2
Enter marks 1: 112
Invalid marks.. try again...
Enter marks 1: 49
Enter marks 2: 60
Number of marks more than 50 is 1

Note: This program can be written in a structured way.
__________________
JOM TOLAK SYIAH & WAHABI!!
Reply With Quote
Paid Advertisement
  #2  
Old 22-06-2018, 10:56 AM
kickdafella kickdafella is offline
Regular

kickdafella's Avatar
 
Trader Rating: (2)
Join Date: Oct 2010
Posts: 463
Thanks (Received): 0
Likes (Received): 3
Active Level
My Mood:
Default

package javaexercises.arrays;

import java.util.Scanner;


public class GradesAverage {

private final int LOWEST_GRADE = 0;
private final int HIGHEST_GRADE = 100;

// student's grades
private int[] grades;

private Scanner in;

/**
* Enter program's point.
*
* @param args
*/
public static void main(String[] args)
{
GradesAverage aGradesAverage = new GradesAverage();
aGradesAverage.in = new Scanner(System.in);

System.out.print("Enter the number of students: ");
int numStudents = aGradesAverage.in.nextInt();

aGradesAverage.run(numStudents);
**

/**
* Run program.
*
* @param numStudents
*/
private void run(int numStudents)
{
if (numStudents <= 0) {
System.out.println("Invalid number of students.");
return;
**
grades = new int[numStudents];

double sum = 0;
int i = 0;
while (i < numStudents)
{
System.out.printf("Enter the grade for student %1$d: ", (i+1));
int grade = in.nextInt();

// chek if grade is between 0 and 100
if ((grade >= LOWEST_GRADE) && (grade <= HIGHEST_GRADE)) {
grades[i] = grade;
sum += grade;
i++;
continue;
**
System.out.println("Invalid grade, try again...");
**
System.out.printf("The average is %1$.2f\n", (sum / numStudents));
**

**
Reply With Quote
Likes Sniper, hackerism_11, Don Malaya liked this post
  #3  
Old 22-06-2018, 11:19 AM
hackerism_11 hackerism_11 is offline
Regular

hackerism_11's Avatar
 
Trader Rating: (0)
Join Date: Mar 2013
Posts: 469
Thanks (Received): 0
Likes (Received): 15
Active Level
Default

Quote:
Originally Posted by kickdafella View Post
package javaexercises.arrays;

import java.util.Scanner;


public class GradesAverage {

private final int LOWEST_GRADE = 0;
private final int HIGHEST_GRADE = 100;

// student's grades
private int[] grades;

private Scanner in;

/**
* Enter program's point.
*
* @param args
*/
public static void main(String[] args)
{
GradesAverage aGradesAverage = new GradesAverage();
aGradesAverage.in = new Scanner(System.in);

System.out.print("Enter the number of students: ");
int numStudents = aGradesAverage.in.nextInt();

aGradesAverage.run(numStudents);
**

/**
* Run program.
*
* @param numStudents
*/
private void run(int numStudents)
{
if (numStudents <= 0) {
System.out.println("Invalid number of students.");
return;
**
grades = new int[numStudents];

double sum = 0;
int i = 0;
while (i < numStudents)
{
System.out.printf("Enter the grade for student %1$d: ", (i+1));
int grade = in.nextInt();

// chek if grade is between 0 and 100
if ((grade >= LOWEST_GRADE) && (grade <= HIGHEST_GRADE)) {
grades[i] = grade;
sum += grade;
i++;
continue;
**
System.out.println("Invalid grade, try again...");
**
System.out.printf("The average is %1$.2f\n", (sum / numStudents));
**

**
wah.. power2..
slalu java ni pakai software ape ? yang den tau dev c++
__________________
manusia ni panjang angan-angan, sedangkan dia tak berupaya utk sampai dan MAUT sudah menjemputnya.
Reply With Quote
  #4  
Old 22-06-2018, 02:17 PM
TyCo86 TyCo86 is offline
Regular

TyCo86's Avatar
 
Trader Rating: (0)
Join Date: Sep 2013
Posts: 227
Thanks (Received): 0
Likes (Received): 0
Blog Entries: 1
Active Level
My Mood:
Default

Quote:
Originally Posted by kickdafella View Post
package javaexercises.arrays;

import java.util.Scanner;


public class GradesAverage {

private final int LOWEST_GRADE = 0;
private final int HIGHEST_GRADE = 100;

// student's grades
private int[] grades;

private Scanner in;

/**
* Enter program's point.
*
* @param args
*/
public static void main(String[] args)
{
GradesAverage aGradesAverage = new GradesAverage();
aGradesAverage.in = new Scanner(System.in);

System.out.print("Enter the number of students: ");
int numStudents = aGradesAverage.in.nextInt();

aGradesAverage.run(numStudents);
**

/**
* Run program.
*
* @param numStudents
*/
private void run(int numStudents)
{
if (numStudents <= 0) {
System.out.println("Invalid number of students.");
return;
**
grades = new int[numStudents];

double sum = 0;
int i = 0;
while (i < numStudents)
{
System.out.printf("Enter the grade for student %1$d: ", (i+1));
int grade = in.nextInt();

// chek if grade is between 0 and 100
if ((grade >= LOWEST_GRADE) && (grade <= HIGHEST_GRADE)) {
grades[i] = grade;
sum += grade;
i++;
continue;
**
System.out.println("Invalid grade, try again...");
**
System.out.printf("The average is %1$.2f\n", (sum / numStudents));
**

**
ambil dri cni https://github.com/java-tester-x/jav...esAverage.java ka bro?dah try code nie tpi ada error..
__________________
JOM TOLAK SYIAH & WAHABI!!
Reply With Quote
  #5  
Old 22-06-2018, 02:26 PM
dell dell is offline
Super Active

dell's Avatar
 
Trader Rating: (5)
Join Date: Apr 2007
Location: Johor Bahru
Posts: 7,905
Thanks (Received): 24
Likes (Received): 10
Active Level
My Mood:
Default

..pakai c++
__________________
Jaybeerean.....
Reply With Quote
  #6  
Old 22-06-2018, 03:39 PM
TyCo86 TyCo86 is offline
Regular

TyCo86's Avatar
 
Trader Rating: (0)
Join Date: Sep 2013
Posts: 227
Thanks (Received): 0
Likes (Received): 0
Blog Entries: 1
Active Level
My Mood:
Default

Quote:
Originally Posted by dell View Post
..pakai c++
Saya pakai java development kit jer..
__________________
JOM TOLAK SYIAH & WAHABI!!
Reply With Quote
  #7  
Old 30-08-2018, 03:50 AM
Vpoint7 Vpoint7 is offline
Regular

Vpoint7's Avatar
 
Trader Rating: (0)
Join Date: Feb 2009
Posts: 222
Thanks (Received): 8
Likes (Received): 7
Active Level
My Mood:
Default

Quote:
Originally Posted by TyCo86 View Post
Assalammualaikum kepada member2 CG yang expert dlm Java. Boleh berikan bantuan untuk jawab soalan Java di bawah nie?

Write a program in Java called Marks, which prompts user for the number of marks, reads it from the keyboard, and saves it in an int variable called numOfMarks. It then prompts user for the marks and saves them in an int array called marks. Your program shall check that the marks value is between 0 and 100 and the number of marks is between 1 to 30. The program should display number of marks that are more than 50. An example of output is shown below:


Enter the number of marks: 2
Enter marks 1: 112
Invalid marks.. try again...
Enter marks 1: 49
Enter marks 2: 60
Number of marks more than 50 is 1

Note: This program can be written in a structured way.

Quote:
Originally Posted by kickdafella
ambil dri cni https://github.com/java-tester-x/jav...esAverage.java ka bro?dah try code nie tpi ada error..
Soalan ni dah dpt jawapan ke ?

Hmm... sy cuba jawabkan soalan ini wlaupn tak pro, sambil guna code yg dikatakan error tu.. Sbnrnya soalan TyCo86 tak boleh pakai direct dgn jwpn kickdafella dari github tu, sbb asal soalan adalah berbeza, jwpn mesti lah lain kan ?

Tapi kalau nak cuba jugak guna jwpn tu, jom kita kasi buat smpi jadi utk soalan tn TyCo86. Saya cuba kan... kwn2 lain, jika ada cara masing2, bantu lah tn TyCo86..
Ada lagi cara lain, cuma sy gunakan konsep serupa, tn TyCo86 mgkn dah cuba tgk code github tu sblm ni, kali ini tgk sekali lagi & lihat perbezaan dgn kesesuaian soalan...

Code dari github itu xde error sbnrnya, hanya perlu betulkan curly braces sahaja.. baru boleh run dgn baik...

Saya buatkan video tutorial utk ini, senang sikit nak faham konsep, dan nmpk laluan nya, klu terus letak copy-paste code, risau ade missing bracket..

Mohon rujuk disini, sy letak di domain website peribadi.. harap membantu...
Code:
http://warisanbernama.com/video/JavaTutorial.mp4
Rujuk video utk perbandingan sblm nak copy-paste code -> Gantikan simbol ** kpd yg sepatutnya
Code:
/* 
Enter the number of marks: 2
Enter marks 1: 112
Invalid marks.. try again...
Enter marks 1: 49
Enter marks 2: 60
Number of marks more than 50 is 1

1. Java called Marks
2. Read from keyboard & saves in INT - variable called numOfMarks
3. Program should check marks between 0-100, quantity of marks, also between 1-30.
4. Display marks more than 50.

*/

import java.util.Scanner;
public class Marks {

	/* kalau tidak guna bahagian ini pun boleh, ditukar dgn menggunakan angka */
	private final int LOW_MARKS = 0;
	private final int HIGH_MARKS = 100;
	private final int MEDIUM_MARKS = 50;
	
	private int[] marks;
	private Scanner in;

	public static void main(String[] args) {
	
	Marks aMarks = new Marks();
	aMarks.in = new Scanner(System.in);
	
	System.out.print("Enter the number of marks: ");
	int numOfMarks = aMarks.in.nextInt();
	
	aMarks.run(numOfMarks);	
	**	
	private void run(int numOfMarks) {	
		if (numOfMarks < 1 || numOfMarks > 30) {
		System.out.println("Invalid number of marks, please enter between 1-30 only");
		return;		
		**		
		marks = new int[numOfMarks];
		int a = 0;
		int i = 0;					
		while (i < numOfMarks) {
			System.out.printf("Enter marks %1$d: ", (i+1));
			int marks = in.nextInt();

			//kuantiti markah lebih drpd 50
			if (marks >= MEDIUM_MARKS && marks <= HIGH_MARKS) {
				a++; // a = a + 1	
			**

			//markah mesti dlm lingkungan 1-100 sahaja	
			if ((marks > LOW_MARKS) && (marks <= HIGH_MARKS)) {
			        i++;
			        continue;					
			**			
			System.out.println("Invalid marks.. try again...");						
		**
		System.out.println("Number of marks more than 50 is "+ a);
	**
**
__________________
https://warisanbernama.com

Last edited by Vpoint7; 31-08-2018 at 01:10 PM.. Reason: Betul kan ayat skit... & letak code utk memudahkan..
Reply With Quote
  #8  
Old 30-08-2018, 02:12 PM
tomi tomi is online now
Active Member

 
Trader Rating: (0)
Join Date: Mar 2015
Posts: 1,478
Thanks (Received): 1
Likes (Received): 363
Active Level
Default

Quote:
Originally Posted by TyCo86 View Post
Assalammualaikum kepada member2 CG yang expert dlm Java. Boleh berikan bantuan untuk jawab soalan Java di bawah nie?

Write a program in Java called Marks, which prompts user for the number of marks, reads it from the keyboard, and saves it in an int variable called numOfMarks. It then prompts user for the marks and saves them in an int array called marks. Your program shall check that the marks value is between 0 and 100 and the number of marks is between 1 to 30. The program should display number of marks that are more than 50. An example of output is shown below:


Enter the number of marks: 2
Enter marks 1: 112
Invalid marks.. try again...
Enter marks 1: 49
Enter marks 2: 60
Number of marks more than 50 is 1

Note: This program can be written in a structured way.
seeloknya belajar coding step by step.

pecahkan setiap masalah dan cuba code untuk setiap satu, kalau terus nak buat complete code memang rasa susah.
Reply With Quote
Likes mutanic liked this post
  #9  
Old 31-08-2018, 03:41 PM
Vpoint7 Vpoint7 is offline
Regular

Vpoint7's Avatar
 
Trader Rating: (0)
Join Date: Feb 2009
Posts: 222
Thanks (Received): 8
Likes (Received): 7
Active Level
My Mood:
Default

Setuju dgn nasihat tomi, sy harap jwpn di atas boleh run tanpa sebarang error...
__________________
https://warisanbernama.com
Reply With Quote
  #10  
Old 30-10-2018, 01:01 PM
Burhanuddin Burhanuddin is online now
Active Member

Burhanuddin's Avatar
 
Trader Rating: (3)
Join Date: Sep 2008
Posts: 1,767
Thanks (Received): 41
Likes (Received): 2
Active Level
My Mood:
Default

Rasanya dah lama soalan ni, dah boleh post jawapan.

Klik sini untuk banding jawapan.

Cara ni ikut nasihat tomi, pecahkan masalah, jadi untuk setiap masalah tu saya letak dalam satu method/function.

Last edited by Burhanuddin; 30-10-2018 at 01:10 PM..
Reply With Quote
Likes mutanic liked this post
Sponsored Links
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

AMP
Forum Jump