Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3438716
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:13:17+00:00 2026-05-18T08:13:17+00:00

I have written a java class for my class project, and all of my

  • 0

I have written a java class for my class project, and all of my methods are are void, and I basically do nothing but call the methods in my main method.

The code basically helps students manage their monthly income, in terms of rent and loan payments.

Can someone point me in the right direction as to what im doing wrong?
Any advice in general in terms of coding habits?

the class code:

import java.io.*;
import java.util.*;
public class Finance{
  private double rentExpenses, tuition, totalCost, totCost, rent;
  private double payInput;
  private boolean status, liveWithParent;
  private int pay;
  //totalCost=Final cost per month
  //totCost=cost of tuition and rent per month


//Living with parents?
  public void liveWithParents(){
    Scanner in=new Scanner(System.in);
    System.out.println("Are you living with your parents?");
    String parents= in.nextLine();
    if(parents.charAt(0)=='y' || parents.charAt(0)=='Y'){
      status=true;}
    else{
      status=false;}}

//If yes, do you pay them rent?, if yes how much? else -, else How much is your monthly rent anyway?
  public void amountRent(){
    double rent;
    char valid;
    String validIn;
    Scanner in=new Scanner(System.in);
    if(status){
      System.out.println("Do you need to pay them rent?");
      validIn=in.nextLine();
      valid= validIn.charAt(0);
      if(valid=='y' || valid=='Y'){
        System.out.println("How much is your rent?");
        rent=in.nextDouble();}}
    else{
     System.out.println("How much is your monthly rent?");
     rent=in.nextDouble();}}

//What is your college tuition, $/term
  public void collegeTuition(){
    System.out.println("What what is your college tuition in $ per term?");
    Scanner in=new Scanner(System.in);
    tuition= in.nextDouble();}

//Total cost of tuition and rent per month
  public void getMonthlyCost(){
    totCost= rentExpenses + tuition/3.75;
    System.out.println("Your rent expenses and college tuition are: $"+totCost+" per month");}

//Method of paying for expenses

  public void payMethod(){
    Scanner in=new Scanner(System.in);
    System.out.println("How will you pay for your expenses?"
                      + "\n 1 -Savings\n 2 -Loans\n 3 -Freelance Work");
    pay=in.nextInt();
    while(pay<=0 || pay>3){
      System.out.println("You need to enter a number coresponding to the three choiches.\n\t Try again:");
      System.out.println("How will you pay for your expenses?"
                      + "\n 1 -Savings\n 2 -Loans\n 3 -Freelance Work");
      pay=in.nextInt();}}

//Gets the amount of savings the user has and converts
//that value to a monthly value
public void inputPayMethod(){
  Scanner in=new Scanner(System.in);
  if(pay==1){
    System.out.println("What amount of savings do you have in total for the school year?");
    payInput=in.nextDouble();
    payInput=payInput/9;}
  else if(pay==2){
    System.out.println("What amount of loans did you acquire for this school year?");
    payInput=in.nextDouble();
    payInput=payInput/9;}
  else if(pay==3){
    System.out.println("How much revenue does your Freelane business get per month?");
    payInput=in.nextDouble();}}

//Calculates the total cost that the user needs
//for renting and tuition solely
public void getTotalCost(){
 totalCost=(payInput/3.75)-(rentExpenses + tuition/4.348);}

//Outputs the total cost
public void outputCost(){
  System.out.println("Your balance per month after expenses is: $"
                       +totalCost);
  if(totalCost<0){
           System.out.println("You still need $"+(-totalCost)+" per months");}
  if(totalCost>0){
           System.out.println("In other words you should be A-O-KAY");}  
              //Balance calculation for an entire school year
           System.out.println("For an entire school year, your expenses would be: "+ 
                                (totalCost*2));}

//Create a file with the information entered 
//and the information processed
public void outputFile() throws IOException{
 String payFileOutput=null;
 Scanner in=new Scanner(System.in);
 System.out.println("Enter the name of the file you wish to store this"+
                     "information in: ");
    String fileName= in.nextLine();

     PrintWriter file= new PrintWriter(fileName);
     file.println("Your rent expenses are                      :"+rentExpenses);
     file.println("Your college tuition in dollars per month is:"+tuition);
     file.println("                                             -----");
     file.println("Your rent expenses and college tuition are  :"+(rentExpenses + tuition));
     if(pay==1)
      payFileOutput="Savings";
     else if(pay==2)
      payFileOutput="Loans";
     else if(pay==3)
      payFileOutput="Freelance Work";
     else
      ;
     file.println("\n\nYou choose "+payFileOutput+"as your income source");
     file.println("Your balance per month after expenses is: $"+totalCost);
     if(totalCost<0){
      file.println("You still need $"+(-totalCost)+"per month");}
     if(totalCost>0){
      file.println("\n\n\nYour budget seems good");}
     file.close();
     System.exit(0);}


}

//The main method: import java.io.*; public class UseClass { /** * @param args */ public static void main(String[] args) throws IOException{ Finance fin=new Finance(); fin.liveWithParents(); fin.amountRent(); fin.collegeTuition(); fin.getMonthlyCost(); fin.payMethod(); fin.inputPayMethod(); fin.getTotalCost(); fin.outputCost(); fin.outputFile(); } }

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:13:18+00:00Added an answer on May 18, 2026 at 8:13 am

    The first thing that comes to mind is you need to separate your concerns. This means your Finance class should only do things related to finance. It should not do things like read input from the command line.

    A way to achieve this separation would be to create another class, something like FinanceDataReader or something, and have it manage all the user interactions. It would get the data from the command line and feed it to your Finance instances. If you really wanted to get fancy, you create an interface for reading finance data, and then have a CommandLineFinanceDataReader implementation. That way you could change how you get data in the future, and not have to change your Finance class.

    So, to say it another way, move any functionality that reads input into another class, to make Finance smaller and more maintainable. Build up classes that encapsulate all your functionality, but group them according to the concerns you are addressing.

    Another big thing you can do is use a framework like JUnit to unit test your code. It will take an upfront investment, but it will help you save time, because you will test all the small bits as you go. In other words, you wont write 300 lines of code and then have to figure out why its not working; testing as you write each method will help you ensure your methods/classes are doing what you want.

    Don’t worry, this sort of things comes with time — if this is for your first Java and possibly OO class, you will make mistakes and have limited design. That will improve with time if you stick with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that adds elements to an AutoCad drawing. I noticed that
i have a input tag which is non editable, but some times i need
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
I have found this example on StackOverflow: var people = new List<Person> { new
I have a login.jsp page which contains a login form. Once logged in the
Let say I have the following desire, to simplify the IConvertible's to allow me
I want to have generalised email templates. Currently I have multiple email templates with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.