Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Need assistance in Java

I don't know how to deal with this assignment i have to do, this is what i currently have done

/**
 * @(#)sample.java
 *
 *
 * @author 
 * @version 1.00 2017/10/25
 */

import java.util.Scanner;//start class
public class sample {//start main

public static void main(String[] args) {//start main
Scanner input = new Scanner(System.in);
System.out.println("[Computer Science Classroom1A]");

//declare variables
int lowest=0,highest=101,average=0,total=0;
int grade;

//for loop to take user input
for (int i=1;i<=5;i++){
System.out.println("Please enter Studentgrade:"+i);
grade=input.nextInt();

//do maths get total
total=total+grade;

//if statements to get highest to lowest
if(grade>=highest){
highest=grade;
}//end if
if(grade<=lowest){
lowest=grade;
}//end if

}//end for loop

//do maths get average
average=total/5;

//final printout
System.out.println("The HIGHESTGRADE is:"+highest);
System.out.println("The LOWESTGRADE is:"+lowest);
System.out.println("The TOTALGRADE is:"+total);
System.out.println("The AVR GRADE is"+average);

    }//end main
}//end class



these are the tasks that i have to do:

Brief/Task:

You are required to write a program (java class) for entering grades for two class groups.
Use a while loop for one class group and a  for loop for the other class group. 
The user should be asked before entering each class group, how many students are in the class and the loop will execute that many times to take in the grades.
Count the number of fails and passes in each class group. (Pass mark is 50%) 
The output from the program will tell the user the highest and lowest grade achieved from each class group, and the average grade from each class group.
Finally the program will tell the user the name of the class group that got the better average or if both classes got the same average.


Can someone help me quick with these tasks because i honestly don't know how to do this, my professor is a dumbass and whenever i ask him a question he either says i need to know these stuff or just corrects minor mistakes i do, he never explains anything, and only praises the ones that already have experience outside of college with java. Best possible scenario would be if someone just sent me the program made and i could just copy paste it, it doesn't take long at all since i saw people in my class doing it in 15 minutes(the experienced ones). I need to submit the program by midnight so in 7 hours and i also have to do a write up on it and everything in the write up has to do with describing the program, so i can't do the write up either 😭 . Need help asap
Code
Ever heard about this "formatting" thing?
Hey I have a signature.
(Oct 25, 2017 09:49 AM)Sogomn Wrote:  
Code
Ever heard about this "formatting" thing?

no, that's why i need help


/**
 * @(#)Assignment1.java
 *
 *
 * @author 
 * @version 1.00 2017/10/18
 */

import java.util.Scanner;//start 
public class Assignment1 {//start main

public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("[Computer Science Classroom1A]");

           //declare a variables 
           String coursename; 
           // variables for amount of students and grades 
           int numstudents, grade,pass=0,fail=0,highest=0,lowest=101,average,total=0; 

           //user enters num of Students 
           System.out.println("Please enter number of students : "); 
           numstudents = input.nextInt(); 
    
            //start for loop 
           for(int i=1;i<=numstudents; i++){ 
   
               //user enters a grade 
               System.out.println("Enter grade of student  : " + i); 
              grade = input.nextInt(); 
   
              if(grade>49){ 
                   pass++; 
               }// end if 
               else{ 
                   fail++; 
               }// end else 
               
               total= total+grade; 
    
               if(highest<grade){ 
                   highest=grade; 
               }//end if 
               if( lowest>grade){ 
                  lowest=grade; 
               }//end if 
    
            }//end for loop 
    
            average= total/numstudents; 
    System.out.println(" Then number of students is " + numstudents); 
        System.out.println("the number of passes are " +pass); 
            System.out.println("the number of fails are " +fail); 
            System.out.println("the average is " +average); 
            System.out.println("the highest is " +highest); 
            System.out.println("the lowest is " +lowest); 
    
       }// end of main 
   }  // end of class





This is what i made so far, i started something new, but i don't know how to introduce another class using while loop this time and afterwards comparing both classes and which class did better in terms of grades
You just did it again! Format your code or nobody is gonna read it!
Hey I have a signature.
Sogomn is asking you to put code tags around your code, so that it is easier to read in the post.
Try [code*] insert code here [/code] without the *
i think you format it by doing CTRL+A and then ALT+SHIFT+F
not sure, its what i do to neaten it up in Computer science class

EDIT: Dont listen to that, you probably use a different program than me! sorry!
(Nov 2, 2017 09:39 AM)UTellme Wrote:  i think you format it by doing CTRL+A and then ALT+SHIFT+F
not sure, its what i do to neaten it up in Computer science class

EDIT: Dont listen to that, you probably use a different program than me! sorry!

They were talking about formatting forum posts :|
Code
/**
* @(#)Assignment1.java
*
*
* @author
* @version 1.00 2017/10/18
*/

import java.util.Scanner;//start
public class Assignment1 {//start main

public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("[Computer Science Classroom1A]");

           //declare a variables
           String coursename;
           // variables for amount of students and grades
           int numstudents, grade,pass=0,fail=0,highest=0,lowest=101,average,total=0;

           //user enters num of Students
           System.out.println("Please enter number of students : ");
           numstudents = input.nextInt();
    
            //start for loop
           for(int i=1;i<=numstudents; i++){
  
               //user enters a grade
               System.out.println("Enter grade of student  : " + i);
              grade = input.nextInt();
  
              if(grade>49){
                   pass++;
               }// end if
               else{
                   fail++;
               }// end else
              
               total= total+grade;
    
               if(highest<grade){
                   highest=grade;
               }//end if
               if( lowest>grade){
                  lowest=grade;
               }//end if
    
            }//end for loop
    
            average= total/numstudents;
    System.out.println(" Then number of students is " + numstudents);
        System.out.println("the number of passes are " +pass);
            System.out.println("the number of fails are " +fail);
            System.out.println("the average is " +average);
            System.out.println("the highest is " +highest);
            System.out.println("the lowest is " +lowest);
    
       }// end of main
   }  // end of class
Please format the code a lil bit next time OP!
You already have the for loop done, so just do a while loop

Ask the user for number of students.
Create some index starting at 0
While the index is less than students, do what you did for your for loop and make sure to increment your index at the end
You will need to declare a new set of variables for this loop and print it out in addition to your first set of printlns
Would probably be a good idea to state which class the data corresponds with when printing it out, too


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Java] by MesaGFXMay 21, 2019 10:02 AM 1 166 May 21, 2019 10:02 AM
Last Post: A_P_T
[Java] by DimleadDec 4, 2017 12:42 AM 3 190 Dec 4, 2017 12:42 AM
Last Post: Ozgin
[Java] by DimleadNov 7, 2017 12:43 PM 4 209 Nov 7, 2017 12:43 PM
Last Post: UB3R5W4G0V3RL0RD