New Posts  All Forums:Forum Nav:

need help in java Assignment

post #1 of 6
Thread Starter 
Create a new folder called 'assign61' under C:\Java\Lesson6. Copy GPA.java from Lesson 5 Assignment 5.2 (sample solution) into it. Make two copies of that file in the same folder, and rename them to GPAUtil.java and TestGPA.java respectively. Modify the class names to GPAUtil and TestGPA in these two files.
(ii) In the GPAUtil class, remove all methods except gradePoints(). Declare a static "class-level (or global)" 'String' type array variable called 'validDepts' at the beginning of the class. This array needs to have 3 elements: "CS", "EE", "ME".
(iii) Still in the GPAUtil class, write a new static method called validateCourseIdGrade that takes a single parameter called 'courseIdGrade' of type String. Here, 'courseIdGrade' represents a single course ID + grade string (example: "CS101A").

Inside the body of the method:

• Declare a String variable called 'errorMsg' with a value of "NO_ERROR".
• Check if 'courseIdGrade' is exactly 6 char in length; if not, set errorMsg to contain the String: "Course ID/Grade string invalid, must be 6 char".
• If 'courseIdGrade' is exactly 6 char in length, check if dept id exists in 'validDepts'. If not found, set errorMsg to "Dept ID invalid, must be one of: CS, EE, ME". The check must be case-insenstive, so use 'equalsIgnoreCase()' from String type. Return errorMsg at the end of the method.

Note: No need to implement any constructor in GPAUtil; all attributes and methods in it are static.
(iv) Modify GPA.java as described in steps (iv) - (ix) here. First add a constructor that takes a String array called 'courseIdGrades' as the only parameter. Add the following as class-level (instance) attributes (unspecified access specifier):
• a String array called 'courseIdGrades'
• a String array called 'courseIds'
• a char array called 'grades'
• a double called 'gpa'
• a String called 'errorMsg'

Inside the constructor, allocate memory for the courseIds and grades arrays using the 'new' keyword such that each contains as many elements as the 'courseIdGrades' array sent in (Note: The 'courseIdGrades' array will contain the run-time arguments sent in, when you call the constructor in step (x) below).
(v) Still in the GPA class, remove gradePoints() method and modify parseInput(), computeGPA(), and displayResult() in GPA.java so that they do not take the arrays as input anymore, since these arrays are now class attributes (and so can be referred directly in any of the class methods). These methods should now be instance (in other words, not static). Also remove any other redundant parameters and modify the method calls to get the code to compile.
(vi) Write a new method called processData that first calls parseInput() inside it's body. Next it checks if errorMsg attribute of the class is equal to "NO_ERROR". If so, it calls the computeGPA() method. If not, it should display a message: "Input error - details are: " concatenated with the 'errorMsg' variable, and then exit the program.
(vii) Add a call to processData() at the end of the constructor. Now remove the main() method.
(viii) At the beginning of the while loop of parseInput(), add a call to the static method validateCourseIdGrade() of GPAUtil, sending it the current element of the courseIdGrades array. Also change the while loop to now use the break statement if errorMsg does not equal "NO_ERROR" in any iteration. Otherwise, it should set the appropriate elements of courseIds and grades arrays, same as in Assign. 5.2.
(ix) Modify the computeGPA() method to call the static gradePoints() method of GPAUtil, passing it a single grade every time in the loop.
(x) Finally modify TestGPA.java to remove all methods except main(). In the main() method, instantiate an object called 'gpa' of type GPA using the 'new' keyword, passing it the 'args' String array. Note: Java is case-semsitive; GPA is a class type, whereas 'gpa' is an object of type: GPA. After this, call the displayResults() method on the 'gpa' object.
(xi) Compile GPAUtil.java, then GPA.java and finally TestGPA.java and run the code. Verify that the output looks exactly same as in Assignment 5.2, with the difference that you can now test bad data and expect the correct error message to show up. Make sure you test all the test cases shown in the sample output below:
C:\Java\Lesson6\assign61>javac GPAUtil.java

C:\Java\Lesson6\assign61>javac GPA.java

C:\Java\Lesson6\assign61>javac TestGPA.java

C:\Java\Lesson6\assign61>java TestGPA
Please supply grades to find GPA

C:\Java\Lesson6\assign61>java TestGPA CS101 EE102A
Input error: Details are:
Course ID/Grade string invalid, must be 6 char

C:\Java\Lesson6\assign61>java TestGPA CS101B ES102A
Input error: Details are:
Dept ID invalid, must be one of: CS, EE, ME

C:\Java\Lesson6\assign61>java TestGPA cs101B Ee102a

Course Grade
CS101 B
EE102 A
GPA: 3.5

C:\Java\Lesson6\assign61>java TestGPA CS101A CS102B EE103A EE201A

Course Grade
CS101 A
CS102 B
EE103 A
EE201 A
GPA: 3.75
C:\Java\Lesson6\assign61>

(xii) Submit GPA.java, GPAUtil.java and TestGPA.java.
post #2 of 6
Thread Starter 
public class GPAUtil
{
static String validDepts()
{
validDepts[] d = new validDepts[3];
d[0] = new validDepts("CS");
d[1] = new validDepts("EE");
d[2] = new validDepts("ME");
}
static validateCourseIdGrade()
{
String courseIdGrade = String courseID + String grade;


}
static int gradePoints(char grade)
{
int points = 0;
switch(grade)
{
case 'A':
points = 4;
break;
case 'B':
points = 3;
break;
case 'C':
points = 2;
break;
case 'D':
points = 1;
break;
default:
points = 0;
break;
}
return points;
}

static void displayResult(String[] courseIds, char[] grades, double gpa)
{
System.out.println("
");
System.out.println(" Course ID Grade" );
System.out.println("
");
for (int i = 0; i < courseIds.length; i++)
{
System.out.println(" " + courseIds + " " + grades);
}
System.out.println("
");
System.out.println(" GPA = " + gpa);
System.out.println("
");
}
}


I have done so far these much.. if any one can help....
post #3 of 6
Thread Starter 
Please give your advise or help me...
post #4 of 6
Unless you put forth some effort to do your assignments. Then don't expect help.

This assignment requires you to create 3 different classes.
What you have posted is the code for less then one.
You need to make an effort to TRY and do the assignments, if you have problems, then ask for help
Of the last 3 threads that you started you make no attempt to do the assignment your self at all,
Why would you think anyone would help you do your homework if you didn't care to try it your self
You don't even post code the way you were asked to post it. So why should someone help you
if you can not even help your self.

If you want help, make an effort to do the work first your self. When you have a problem ask for help with that problem
and you will get help.



And stop sending PM's.
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
post #5 of 6
Quote:
Originally Posted by tom.slick View Post




And stop sending PM's.

XD biggrin.gif
Bandaids
(15 items)
 
  
MotherboardGraphicsHard DriveOptical Drive
Asrock Z77 Extreme 6 GTX 580 WD 10EALX ASUS DRW 
CoolingOSMonitorMonitor
Havik 140 Windows 7 Ultimate ASUS VH228T Toshiba 32RV600A 
MonitorKeyboardPowerCase
Compaq S2021a Microsoft Wired Keyboard 600 Aero Cool Strike X 1100w Asus Antec 
MouseMouse PadAudio
Logitech MX518 Mionix Ensis 320 Creative 2.1 
  hide details  
Reply
Bandaids
(15 items)
 
  
MotherboardGraphicsHard DriveOptical Drive
Asrock Z77 Extreme 6 GTX 580 WD 10EALX ASUS DRW 
CoolingOSMonitorMonitor
Havik 140 Windows 7 Ultimate ASUS VH228T Toshiba 32RV600A 
MonitorKeyboardPowerCase
Compaq S2021a Microsoft Wired Keyboard 600 Aero Cool Strike X 1100w Asus Antec 
MouseMouse PadAudio
Logitech MX518 Mionix Ensis 320 Creative 2.1 
  hide details  
Reply
post #6 of 6
Quote:
Originally Posted by tom.slick View Post

Unless you put forth some effort to do your assignments. Then don't expect help.

This assignment requires you to create 3 different classes.
What you have posted is the code for less then one.
You need to make an effort to TRY and do the assignments, if you have problems, then ask for help
Of the last 3 threads that you started you make no attempt to do the assignment your self at all,
Why would you think anyone would help you do your homework if you didn't care to try it your self
You don't even post code the way you were asked to post it. So why should someone help you
if you can not even help your self.

If you want help, make an effort to do the work first your self. When you have a problem ask for help with that problem
and you will get help.



And stop sending PM's.

If things go to plan I intend to make some changes regarding this rubbish here wink.gif

shhhh.

XD
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming