![]() |
|
[Java] Need assistance in Java - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] Need assistance in Java (/showthread.php?tid=5742806) |
Need assistance in Java - Dimlead - Oct 25, 2017 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 RE: Need assistance in Java - Sogomn - Oct 25, 2017 Code Ever heard about this "formatting" thing?RE: Need assistance in Java - Dimlead - Oct 25, 2017 (Oct 25, 2017 09:49 AM)Sogomn Wrote: 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 RE: Need assistance in Java - Sogomn - Oct 26, 2017 You just did it again! Format your code or nobody is gonna read it! RE: Need assistance in Java - pyrotheseus - Oct 26, 2017 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 * RE: Need assistance in Java - UTellme - Nov 2, 2017 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! RE: Need assistance in Java - hintss - Nov 2, 2017 (Nov 2, 2017 09:39 AM)UTellme Wrote: i think you format it by doing CTRL+A and then ALT+SHIFT+F They were talking about formatting forum posts :| RE: Need assistance in Java - Nicᴋ - Nov 3, 2017 Code /**RE: Need assistance in Java - Kjetil - Nov 4, 2017 Please format the code a lil bit next time OP! RE: Need assistance in Java - MadZ - Nov 4, 2017 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 |