d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help With Java Object Oriented Program
Add Reply New Topic New Poll
Member
Posts: 1,081
Joined: Aug 25 2013
Gold: Locked
Trader: Scammer
Nov 3 2013 11:32am
Okay so I need to read in the points possible from the user in 5 different categories and store them into an object class called Points

In my main method I have this:

Code
Scanner s = new Scanner(System.in);

System.out.print("Enter in the total possible for Category One : ");
int totalPossiblePointsCategoryOne = Integer.parseInt(s.nextLine());

System.out.print("Enter in the total possible for Category Two : ");
int totalPossiblePointsCategoryTwo = Integer.parseInt(s.nextLine());

System.out.print("Enter in the total possible for Category Three : ");
int totalPossiblePointsCategoryThree = Integer.parseInt(s.nextLine());

System.out.print("Enter in the total possible for Category Four : ");
int totalPossiblePointsCategoryFour = Integer.parseInt(s.nextLine());

System.out.print("Enter in the total possible for Category Five : ");
int totalPossiblePointsCategoryFive = Integer.parseInt(s.nextLine());


How do I store these into a Points object?

my Points class code looks like this:

Code
import java.util.*;

public class Points {
public int totalPossiblePointsCategoryOne;
public int totalPossiblePointsCategoryTwo;
public int totalPossiblePointsCategoryThree;
public int totalPossiblePointsCategoryFour;
public int totalPossiblePointsCategoryFive;
public int totalPossiblePoints;

public Points(int totalPossiblePointsCategoryOne, int totalPossiblePointsCategoryTwo, int totalPossiblePointsCategoryThree, int totalPossiblePointsCategoryFour, int totalPossiblePointsCategoryFive){
this.totalPossiblePointsCategoryOne = totalPossiblePointsCategoryOne;
this.totalPossiblePointsCategoryTwo = totalPossiblePointsCategoryTwo;
this.totalPossiblePointsCategoryThree = totalPossiblePointsCategoryThree;
this.totalPossiblePointsCategoryFour= totalPossiblePointsCategoryFour;
this.totalPossiblePointsCategoryFive = totalPossiblePointsCategoryFive;
this.totalPossiblePoints = totalPossiblePointsCategoryOne + totalPossiblePointsCategoryTwo + totalPossiblePointsCategoryThree + totalPossiblePointsCategoryFour + totalPossiblePointsCategoryFive;
}

public int getTotalPossiblePoints(){
return totalPossiblePoints;
}
}


I need to use the total possible points for each category and store them in an object called points. I then need to add up all of those to get a grand total possible points that I can use to find out weighted scores.

I need to store the weighted scores as well.
weightedCategoryOne = 15% of totalPossiblePoints
weightedCategoryTwo = 15% of totalPossiblePoints
weightedCategoryThree = 30% of totalPossiblePoints
weightedCategoryFour = 10% of totalPossiblePoints
weightedCategoryFive = 30% of totalPossiblePoints.

for example:
totalPossiblePointsCategoryOne = 200
totalPossiblePointsCategoryTwo = 400
totalPossiblePointsCategoryThree = 300
totalPossiblePointsCategoryFour = 75
totalPossiblePointsCategoryFive = 25

then totalPossiblePoints = 1000

Category One = 15% of totalPossiblePoints so weightedCategoryOne = 150
Category Two = 15% of totalPossiblePoints so weightedCategoryTwo = 150
Category Three = 30% of totalPossiblePoints so weightedCategoryThree = 300
Category Four = 10% of totalPossiblePoints so weightedCategoryFour = 100
CategoryFive = 30% of totalPossiblePoints so weightedCategoryFive = 300

after those are stored, i get user's input on playerOnes scores in each category.
so lets say playerOne scored the following:
Category 1: 150 of 200
Category 2: 380 of 400
Cetegory 3: 270 of 300
Category 4: 60 of 75
Category 5: 15 of 25

I need to then figure out the adjusted scores he got based on the weighted category points so for playerOne on category one it would be (150/200)*150 would be his weighted score in category one.
playerOneWeightedScoreCategoryOne = (150/200)*150
playerOneWeightedScoreCategoryTwo = (380/400)*150
playerOneWeightedScoreCategoryThree = (270/300)*300
playerOneWeightedScoreCategoryFour = (60/75)*100
playerOneWeightedScoreCategoryFive = (15/25)*300
playerOneTotalWeightedScore = playerOneWeightedScoreCategoryOne + playerOneWeightedScoreCategoryTwo + playerOneWeightedScoreCategoryThree + playerOneWeightedScoreCategoryFour + playerOneWeightedScoreCategoryFive
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 3 2013 12:08pm
good god your variable names are too long.

Quote (GetSpanked @ Nov 3 2013 01:32pm)
Okay so I need to read in the points possible from the user in 5 different categories and store them into an object class called Points

In my main method I have this:

Code
Scanner s = new Scanner(System.in);

  System.out.print("Enter in the total possible for Category One : ");
  int totalPossiblePointsCategoryOne = Integer.parseInt(s.nextLine());

  System.out.print("Enter in the total possible for Category Two : ");
  int totalPossiblePointsCategoryTwo = Integer.parseInt(s.nextLine());

  System.out.print("Enter in the total possible for Category Three : ");
  int totalPossiblePointsCategoryThree = Integer.parseInt(s.nextLine());

  System.out.print("Enter in the total possible for Category Four : ");
  int totalPossiblePointsCategoryFour = Integer.parseInt(s.nextLine());

  System.out.print("Enter in the total possible for Category Five : ");
  int totalPossiblePointsCategoryFive = Integer.parseInt(s.nextLine());


How do I store these into a Points object?

You call the constructor.
Points p = new Points(totalPossiblePointsCategoryOne, totalPossiblePointsCategoryTwo, ...);

This post was edited by carteblanche on Nov 3 2013 12:08pm
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Nov 3 2013 01:18pm
Use more arrays!

Code
public int totalPossiblePointsCategoryOne;
public int totalPossiblePointsCategoryTwo;
public int totalPossiblePointsCategoryThree;
public int totalPossiblePointsCategoryFour;
public int totalPossiblePointsCategoryFive;
public int totalPossiblePoints;


can become

Code
int[] total_possible_points;
total_possible_points = new int[10]; // allocates 10 indexes in the array, so they can be used
total_possible_points[1] = 55;

System.out.println( total_possible_points[1] );
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll