Im recieving error codes.
Here is my code it is in two classesCode:Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at sample2.AdditionalMethods.main(AdditionalMethods.java:33)
Code:package sample2; import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JOptionPane; public class AdditionalMethods { /** * @param args */ public static void main(String[] args)throws IOException, FileNotFoundException { // TODO Auto-generated method stub File f = new File("shapes.dat"); Scanner infile = new Scanner(f); String tempname, temptype; int templ=0, tempw=0; shape [] allshapes; int numofshapes = infile.nextInt(); allshapes = new shape[numofshapes]; for (int i = 0; i < numofshapes; i++) allshapes[i] = new shape(); System.out.println(" we now have " + numofshapes + " shape objects"); for (int i = 0; i < numofshapes; i++) { tempname =infile.next(); temptype = infile.next(); allshapes[i].setname(tempname); allshapes[i].settype(temptype); if (temptype.equals("R")) { templ = infile.nextInt(); tempw = infile.nextInt(); allshapes[i].setlength(templ); allshapes[i].setwidth(tempw); } templ = infile.nextInt(); tempw = infile.nextInt(); System.out.println(" the information read is " + tempname+ " " + temptype+ " " + templ+ " " + tempw); } JFrame Win = new JFrame(" my first graphics program"); Win.setSize(500, 500); Win.setLocation(100,100); Win.setVisible(true); Container content = Win.getContentPane(); Graphics g; g = content.getGraphics(); int drawshape = 0; content.setBackground(Color.YELLOW); JOptionPane.showConfirmDialog(null, " Do you want to draw pictures?"); String shapetype = JOptionPane.showInputDialog(null,"Please type R for rectangle" + " C for circle " + " E for ellipse " + "4 for" ); switch (drawshape) { case 1: shapetype = allshapes[0].gettype(); if (shapetype.equals ("R")); g.drawRect(50, 50, allshapes[0].getwidth(), allshapes[0].getlength()); if (shapetype.equals ("C")); g.drawRect(50, 50, allshapes[0].getradius(), allshapes[0].getradius()); if (shapetype.equals ("E")); g.drawRect(50, 50, allshapes[0].getwidth(), allshapes[0].getlength()); case 2: shapetype = allshapes[1].gettype(); if (shapetype.equals ("R")); g.drawRect(50, 50, allshapes[1].getwidth(), allshapes[1].getlength()); if (shapetype.equals ("C")); g.drawRect(50, 50, allshapes[1].getradius(), allshapes[1].getradius()); if (shapetype.equals ("E")); g.drawRect(50, 50, allshapes[1].getwidth(), allshapes[1].getlength()); case 3: shapetype = allshapes[2].gettype(); if (shapetype.equals ("R")); g.drawRect(50, 50, allshapes[2].getwidth(), allshapes[2].getlength()); if (shapetype.equals ("C")); g.drawRect(50, 50, allshapes[2].getradius(), allshapes[2].getradius()); if (shapetype.equals ("E")); g.drawRect(50, 50, allshapes[2].getwidth(), allshapes[2].getlength()); case 4: shapetype = allshapes[3].gettype(); if (shapetype.equals ("R")); g.drawRect(50, 50, allshapes[3].getwidth(), allshapes[3].getlength()); if (shapetype.equals ("C")); g.drawRect(50, 50, allshapes[3].getradius(), allshapes[3].getradius()); if (shapetype.equals ("E")); g.drawRect(50, 50, allshapes[3].getwidth(), allshapes[3].getlength()); } g.drawRect(50, 50, tempw, templ); JOptionPane.showConfirmDialog(null, " Do you want to exit the picture windown?"); Win.dispose(); } }Code:package sample2; public class shape { private String Name; private String type; private int length, width, radius; public shape () { length = 0; width = 0; Name = "unknown"; type = ""; } public void setname(String n) { Name = n; } public void settype(String t) { type = t; } public void setlength(int l){ length = l; } public void setwidth(int w){ width = w; } public void setradius(int r){ radius = r; } public String getname(){ return Name; } public String gettype(){ return type; } public int getlength(){ return length; } public int getwidth() { return width; } public int getradius() { return radius; } //setters/getters. }



Reply With Quote
Bookmarks